FastPrepAdd Two Numeric Strings with Carry

Add Two Numeric Strings with Carry

ZipRecruiter logoZipRecruiter● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

You are given two strings, a and b, representing nonnegative decimal integers. Return their decimal sum as a string.

Perform digit-by-digit addition with carry; the inputs may be too large for fixed-width numeric types.

Function

addNumericStrings(a: String, b: String) → String

Examples

Example 1

a = "999"b = "1"return = "1000"

Adding the final digits produces a carry through all three nines.

Example 2

a = "123"b = "789"return = "912"

Right-to-left addition gives units 2, tens 1, and hundreds 9.

Constraints

  • 1 <= a.length,b.length <= 10000
  • Both inputs contain only decimal digits.
  • Neither input has a leading zero unless it equals "0".

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String addNumericStrings(String a, String b) {
    // Write your code here.
}
a"999"
b"1"
expected"1000"
Checking account…