Deviopath › Python

Add Big Numbers as Strings

Hard · Strings

Some systems pass huge numbers around as strings. Python ints are unlimited, but here you practise the school method: add digit by digit from the right and carry the 1 when a column reaches 10.

Write add_strings(a, b) that returns the sum of two non-negative integers given as digit strings, also as a string. Do NOT convert a whole string with int(). Converting one digit at a time (int("7") or ord(ch) - ord("0")) is fine.

The inputs have no leading zeros (except "0" itself) and can be different lengths.

Next: Longest Substring Without Repeats