Add Strings - Problem

Given two non-negative integers num1 and num2 represented as strings, return the sum of num1 and num2 as a string.

Important constraints:

  • You must solve the problem without using any built-in library for handling large integers (such as BigInteger)
  • You must also not convert the inputs to integers directly

The strings only contain digits and no leading zeros except the number 0 itself.

Input & Output

Example 1 — Basic Addition
$ Input: num1 = "11", num2 = "123"
Output: "134"
💡 Note: Step-by-step: 1+3=4 (rightmost), 1+2=3 (middle), 0+1=1 (leftmost), result is "134"
Example 2 — With Carry
$ Input: num1 = "456", num2 = "77"
Output: "533"
💡 Note: 6+7=13 (write 3, carry 1), 5+7+1=13 (write 3, carry 1), 4+0+1=5, result is "533"
Example 3 — Single Digits
$ Input: num1 = "0", num2 = "0"
Output: "0"
💡 Note: Edge case: 0 + 0 = 0, simplest possible addition

Constraints

  • 1 ≤ num1.length, num2.length ≤ 104
  • num1 and num2 consist of only digits
  • num1 and num2 don't have any leading zeros except for the zero itself

Visualization

Tap to expand
Add Strings: Process OverviewInputnum1 = "456"num2 = "123"ProcessRight to Left:6 + 3 = 95 + 2 = 74 + 1 = 5Build: "579"Outputresult = "579"No Integer Conversion Required!Handles arbitrarily large numbers as strings
Understanding the Visualization
1
Input
Two number strings num1 and num2
2
Process
Add digits right-to-left with carry
3
Output
Sum as string without converting to integer
Key Takeaway
🎯 Key Insight: Simulate elementary school addition digit-by-digit to handle large numbers without integer conversion
Asked in
Facebook 35 Google 28 Amazon 22 Microsoft 18
185.0K Views
Medium Frequency
~15 min Avg. Time
3.2K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen