Ctrl K

Adding Long Numbers in Strings

Easy
You are given two strings left and right, each the decimal form of a non-negative integer. The numbers can be very long. Return their sum as a string. You may not convert a whole string into a number or rely on built-in big-number arithmetic — add them digit by digit. The inputs have no leading zeros (except for the string "0" itself), and the answer must not have any either.
Example 1
left='2049', right='77' → '2126'

2049 + 77 = 2126.

Example 2
left='999', right='1' → '1000'

The carry runs through all three digits and the answer grows by one digit: 1000.

Example 3
left='0', right='58' → '58'

0 + 58 = 58.

Constraints
  • 1 ≤ left.length, right.length ≤ 10⁴
  • Both strings contain digits only
  • No leading zeros, except for the string "0" itself
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyCounting Off by Threes and Fives EasyTop of a Digit Pyramid EasyMultiplying Digit Strings MediumMultiply Complex Numbers in Strings Medium
loading Python…
Input
left='2049', right='77'
Expected
'2126'

Run checks the first 3 tests in your browser. Submit checks all 93 tests on the server, hidden ones included.