Given two numbers A and B, the task is to find the number of carry operations required when two numbers are added
Note: Both numbers are always of the same length.
 
Example 1:
Input:
A = 1234
B = 5678
Output: 
2
Explanation:
1234
+
5678
--------
6912
--------
4+8 = 2 and carry 1
carry+3+7 = carry 1
carry+2+6 = 9, carry 0
carry+1+5 = 6
So, there are 2 Carry Operations.
Example 2:
Input:
A = 555
B = 555
Output: 
3
Explanation:
555
+
555
--------
1110
--------
5+5 = 0 and carry 1
carry+5+5 = 0 carry 1
carry+5+5 = 0, carry 1
So, there are 3 Carry Operations.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function countCarry() which takes two Integers A and B and returns the answer.
 
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= A, B <= 10^{18}

Difficulty: EASY
Tags: String algorithms

Data structures

Mathematics
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
#User function Template for python3



class Solution:

    def countCarry(self, A , B):

        # code here

Solutions:
class Solution:

	def countCarry(self, A, B):
		carry = 0
		A = str(A)[::-1]
		B = str(B)[::-1]
		c = 0
		for i in range(len(A)):
			a = int(A[i])
			b = int(B[i])
			summ = a + b + carry
			if summ > 9:
				carry = 1
				c += 1
			else:
				carry = 0
		return c


class Solution:

	def countCarry(self, A, B):
		(A, B) = (str(A), str(B))
		(i, j, temp, carry) = (len(A) - 1, len(B) - 1, 0, 0)
		for _ in range(len(A)):
			a = int(A[i]) + int(B[j]) + temp
			temp = 0
			if a > 9:
				temp = a // 10
				carry += 1
			j -= 1
			i -= 1
		return carry


class Solution:

	def countCarry(self, A, B):
		A = str(A)
		B = str(B)
		carry = 0
		c = 0
		for i in range(min(len(A), len(B)) - 1, -1, -1):
			if carry:
				c += 1
			temp = int(A[i]) + int(B[i]) + carry
			carry = temp // 10
		if carry:
			c += 1
		return c


class Solution:

	def countCarry(self, a, b):
		a = str(a)
		b = str(b)
		carry = 0
		count = 0
		n = len(a)
		for i in range(n - 1, -1, -1):
			r = carry + int(a[i]) + int(b[i])
			t = str(r)
			l = len(t)
			carry = 0
			if l > 1:
				carry += int(t[0])
				count += int(t[0])
		return count


class Solution:

	def countCarry(self, A, B):
		a = str(A)[::-1]
		b = str(B)[::-1]
		carry = 0
		k = 0
		for i in range(len(a)):
			s = int(a[i]) + int(b[i]) + carry
			if s >= 10:
				carry = s // 10
				k = k + 1
			elif s < 10:
				carry = 0
		return k


class Solution:

	def countCarry(self, A, B):
		(car, c) = (0, 0)
		while A != 0 and B != 0:
			(r1, r2) = (A % 10, B % 10)
			if car + r1 + r2 >= 10:
				car = (car + r1 + r2) // 10
				c += 1
			else:
				car = 0
			A = A // 10
			B = B // 10
		return c


class Solution:

	def countCarry(self, A, B):
		count = 0
		A = list(str(A))
		B = list(str(B))
		for i in range(len(A) - 1, -1, -1):
			a = int(A[i])
			b = int(B[i])
			if a + b > 9:
				if i == 0:
					count += 1
				else:
					count += 1
					A[i - 1] = str(int(A[i - 1]) + 1)
		return count


class Solution:

	def countCarry(self, A, B):
		A = str(A)[::-1]
		B = str(B)[::-1]
		n = len(A)
		count = 0
		carry = 0
		for i in range(n):
			summa = int(A[i]) + int(B[i]) + carry
			carry = summa >= 10
			count += carry
		return count


class Solution:

	def countCarry(self, A, B):
		strA = str(A)
		strB = str(B)
		carry_count = 0
		carry = 0
		for i in range(len(strA) - 1, -1, -1):
			if int(strA[i]) + int(strB[i]) + carry > 9:
				carry = 1
				carry_count += 1
			else:
				carry = 0
		return carry_count


class Solution:

	def countCarry(self, A, B):
		c = 0
		cnt = 0
		sum = 0
		while A and B:
			d = A % 10
			A = A // 10
			e = B % 10
			B = B // 10
			sum = e + d + c
			if sum > 9:
				cnt += 1
				c = 1
			else:
				c = 0
		return cnt


class Solution:

	def countCarry(self, A, B):
		n = len(str(A))
		c = 0
		r = 0
		while A != 0 and B != 0:
			x = A % 10
			y = B % 10
			if x + y + c > 9:
				r += 1
				c = (x + y + c) // 10
			else:
				c = 0
			A //= 10
			B //= 10
		return r


class Solution:

	def countCarry(self, A, B):
		count = 0
		carry = 0
		while A and B:
			d1 = A % 10
			d2 = B % 10
			carry = (d1 + d2 + carry) // 10
			if carry > 0:
				count += 1
			A //= 10
			B //= 10
		return count


class Solution:

	def countCarry(self, A, B):
		carry = 0
		c = 0
		for i in range(len(str(A))):
			t1 = A % 10
			A = A // 10
			t2 = B % 10
			B = B // 10
			s = t1 + t2 + carry
			if s > 9:
				c += 1
				carry = s // 10
			else:
				carry = 0
		return c


class Solution:

	def countCarry(self, A, B):
		a = str(A)
		b = str(B)
		g = 0
		c = 0
		for i in range(len(a) - 1, -1, -1):
			if int(a[i]) + int(b[i]) + c >= 10:
				c = 1
				g += 1
			else:
				c = 0
		return g


class Solution:

	def countCarry(self, A, B):
		c = 0
		p = 0
		while A and B:
			d1 = A % 10
			d2 = B % 10
			c = (d1 + d2 + c) // 10
			if c > 0:
				p += 1
			A //= 10
			B //= 10
		return p


class Solution:

	def countCarry(self, A, B):
		prev = 0
		c = 0
		j = -1
		A = str(A)
		B = str(B)
		while j >= -len(A):
			temp = int(A[j]) + int(B[j]) + prev
			if temp > 9:
				prev = 1
				c += 1
			else:
				prev = 0
			j -= 1
		return c


class Solution:

	def countCarry(self, A, B):
		A = str(A)
		B = str(B)
		carry = 0
		count = 0
		n = len(A)
		for i in range(n - 1, -1, -1):
			r = carry + int(A[i]) + int(B[i])
			t = str(r)
			l = len(t)
			carry = 0
			if l > 1:
				carry += int(t[0])
				count += int(t[0])
		return count


class Solution:

	def countCarry(self, A, B):
		g = 0
		d = str(A)
		e = str(B)
		c = 0
		for i in range(len(d) - 1, -1, -1):
			f = int(d[i]) + int(e[i]) + c
			if f >= 10:
				c = 1
				g += 1
			else:
				c = 0
		return g


class Solution:

	def countCarry(self, A, B):
		carry = 0
		ans = 0
		while A > 0:
			x = A % 10
			y = B % 10
			if x + y > 9:
				carry = 1
				ans += 1
			elif x + y == 9 and carry:
				ans += 1
			else:
				carry = 0
			A = A // 10
			B = B // 10
		return ans


class Solution:

	def countCarry(self, A, B):
		carry = 0
		carryCount = 0
		A = str(A)
		B = str(B)
		for x in range(len(A) - 1, -1, -1):
			s = carry + int(A[x]) + int(B[x])
			if s > 9:
				carryCount += 1
				if s == 10:
					carry = 1
				else:
					carry = s // 10
			else:
				carry = 0
		return carryCount


class Solution:

	def countCarry(self, A, B):
		carry = 0
		ct = 0
		sa = str(A)
		sb = str(B)
		for i in range(len(sa) - 1, -1, -1):
			if int(sa[i]) + int(sb[i]) + carry > 9:
				ct += 1
				carry = (int(sa[i]) + int(sb[i]) + carry) // 10
			else:
				carry = 0
		return ct


class Solution:

	def countCarry(self, A, B):
		A = str(A)
		B = str(B)
		count = 0
		carry = 0
		for i in range(len(list(A)) - 1, -1, -1):
			if int(A[i]) + int(B[i]) + carry > 9:
				count = count + 1
				carry = int((int(A[i]) + int(B[i]) + carry) / 10)
			else:
				carry = 0
		return count
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B) = map(int, input().split())
		ob = Solution()
		print(ob.countCarry(A, B))


class Solution:

	def countCarry(self, A, B):
		A = str(A)
		B = str(B)
		res = 0
		carry = 0
		for i in range(len(A) - 1, -1, -1):
			add = int(A[i]) + int(B[i]) + res
			if len(str(add)) > 1:
				carry += 1
				res = 1
			else:
				res = 0
		return carry
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B) = map(int, input().split())
		ob = Solution()
		print(ob.countCarry(A, B))


class Solution:

	def countCarry(self, A, B):
		c = 0
		m = 0
		while A != 0:
			d = A % 10
			e = B % 10
			if c + d + e >= 10:
				c = 1
				m += 1
			else:
				c = 0
			A = A // 10
			B = B // 10
		return m
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B) = map(int, input().split())
		ob = Solution()
		print(ob.countCarry(A, B))


class Solution:

	def countCarry(self, A, B):
		A = str(A)
		B = str(B)
		x = 0
		c = 0
		for i in range(len(A) - 1, -1, -1):
			y = int(A[i]) + int(B[i])
			if y + x >= 10:
				c += 1
				x = (y + x) // 10
			else:
				x = 0
		return c
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(A, B) = map(int, input().split())
		ob = Solution()
		print(ob.countCarry(A, B))


class Solution:

	def countCarry(self, A, B):
		(carry, carryNum) = (0, 0)
		while A > 0 and B > 0:
			digit1 = A % 10
			digit2 = B % 10
			digit = digit1 + digit2 + carryNum
			if digit >= 10:
				carry += 1
				carryNum = int(str(digit)[0])
			else:
				carryNum = 0
			A = A // 10
			B = B // 10
		return carry


class Solution:

	def countCarry(self, A, B):
		i = 0
		j = 0
		a = 0
		count = 0
		while A >= 1 and B >= 1:
			i = int(A % 10)
			j = int(B % 10)
			a = a + i + j
			if a >= 10:
				a = 1
				count = count + 1
			else:
				a = 0
			A = int(A // 10)
			B = int(B // 10)
		return count


class Solution:

	def countCarry(self, a, b):
		nc = 0
		a = str(a)[::-1]
		b = str(b)[::-1]
		n = len(a)
		carry = 0
		for i in range(0, n):
			total = int(a[i]) + int(b[i]) + carry
			if total >= 10:
				carry = 1
				nc += 1
			else:
				carry = 0
		return nc


class Solution:

	def countCarry(self, A, B):
		F = str(A)
		g = str(B)
		d = [int(s) for s in F][::-1]
		e = [int(s) for s in list(g)][::-1]
		c = 0
		ans = 0
		for i in range(len(F)):
			if d[i] + e[i] + c > 9:
				c = 1
				ans += 1
			else:
				c = 0
		return ans


class Solution:

	def countCarry(self, A, B):
		ans = 0
		carry = 0
		while A:
			digitA = A % 10
			digitB = B % 10
			carry = (digitA + digitB + carry) // 10
			if carry:
				ans += 1
			A = A // 10
			B = B // 10
		return ans


class Solution:

	def countCarry(self, A, B):
		str_A = str(A)
		n = len(str_A)
		carry = 0
		count = 0
		while A and B:
			rem_A = A % 10
			rem_B = B % 10
			carry = (rem_A + rem_B + carry) // 10
			if carry > 0:
				count += 1
			A = A // 10
			B = B // 10
		return count