Toptal | Live interview (3rd round) | Count carries in sum
Anonymous User
1068

Given two numbers, the task is to find the number of carry operations required when two numbers are added as below.

1234
+
5678
——–
6912
——–

Examples:

Input: n = 1234, k = 5678
Output: 2

4+8 = 2 and carry 1
carry+3+7 = carry 1
carry+2+6 = 9, carry 0
carry+1+5 = 6

Input: n = 555, k = 555
Output: 3

Comments (6)