All questions
Easy2026-08-30

Add Two Large Numbers Represented as Strings

Company
Microsoft
Role

L62 / Senior SDE

Round

Round 1 (DSA)

StringsMathSimulation

Problem Statement

Given two non-negative integers represented as strings, return their sum, also as a string.

You must not use any BigInteger library or convert the entire input to an integer directly (the numbers can be arbitrarily large — beyond 64-bit range).

Constraints

  • 1 <= num1.length, num2.length <= 10^4
  • Both strings contain only digits 0-9
  • No leading zeros (except the number "0" itself)
  • Cannot use built-in big-number libraries

Example

Input: num1 = "9999999999999999999", num2 = "1"

Output: "10000000000000000000"

Input: num1 = "456", num2 = "77"

Output: "533"

What the Interviewer Expects

  1. Simulate grade-school addition — process digits from right to left.
  2. Track carry — sum each pair of digits + carry, append sum % 10, carry sum / 10.
  3. Handle different lengths — use pointers and treat missing digits as 0.
  4. Final carry — don't forget to append a leading 1 if carry remains.
  5. Build result efficiently — append to a list/StringBuilder and reverse at the end (avoid O(n²) string concatenation).

Follow-ups

  1. How would you extend this to multiply two large numbers as strings?
  2. How would you handle subtraction (including negative results)?
  3. What if the numbers are in a base other than 10 (e.g., hexadecimal)?
  4. How would you handle decimal points (floating-point strings)?
🧠

No solution provided

Think through it. That's how you build real interview muscle.

Share: