Add Strings

EasyMathsimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

Two non-negative integers are given as decimal strings num1 and num2. Return their sum, also as a decimal string. Neither input has leading zeros except for the number "0" itself, and the output must not have leading zeros either. Do not convert the whole strings to built-in integers or use a big-integer library; add them digit by digit.

Examples

Input: num1 = "11", num2 = "123"
Output: "134"
11 + 123 = 134.
Input: num1 = "456", num2 = "77"
Output: "533"
The carries ripple through: 6+7 = 13, 5+7+1 = 13, 4+1 = 5.
Input: num1 = "0", num2 = "0"
Output: "0"
The sum is zero.

Constraints

  • 1 <= num1.length, num2.length <= 10^4
  • num1 and num2 contain only digits
  • Neither has leading zeros except the value "0"

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems