Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-128

Add Strings

Problem

Add two non-negative integers given as decimal strings and return their sum as a decimal string, without converting the inputs to integers.

Walk both strings from the right, summing digits plus a carry and emitting the result digit. Any remaining carry becomes a final leading 1.

Hint

Build the result in reverse and flip it at the end; do not forget the final carry.

Test cases

case 1
in: ["11","123"]
expected: "134"
case 2
in: ["0","0"]
expected: "0"
case 3
in: ["999","1"]
expected: "1000"
case 4
in: ["1","9"]
expected: "10"
case 5
in: ["456","77"]
expected: "533"
Starter codePython
def add_strings(num1, num2):
    # Your code here
    pass

5 test cases · run your code against them in the editor