Reported November 2021
ZipRecruiterstring

Add Two Numeric Strings with Carry

Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live ZipRecruiter OA. Under 2s to a working solution.
Founder's read

The trap in this ZipRecruiter OA, reported in November 2021, is the carry that outlives both strings. Add "999" and "1" and a naive loop stops at the shorter length, or forgets the last carry, and returns "000" instead of "1000". The task is simple: add two nonnegative decimal strings digit by digit and return the sum as a string. It's a string and simulation problem, and the inputs run up to 10000 digits, so you can't convert to an int. If you blank on the loop bounds during the live OA, StealthCoder is the invisible safety net that can hand you the solution.

The problem

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".

Reported by candidates. Source: FastPrep

Pattern and pitfall

Walk both strings from the right with two indexes and a carry. Keep looping while either index is still valid or the carry is nonzero. That single condition handles unequal lengths and the final carry in one pass. At each step, read the digit or use 0 if the index ran out, add them with the carry, push sum % 10, and set carry to sum / 10. Build the result in an array of characters, then reverse it at the end. Don't prepend to a string, that turns it into O(n^2) at 10000 digits. Pitfalls: forgetting the trailing carry, mixing up char codes with digit values (subtract '0'), and trying to parse into a number. The constraints rule out leading zeros, so you don't need to strip them. If the loop condition slips your mind under pressure, StealthCoder running during the live OA can cover that gap.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Add Two Numeric Strings with Carry cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as add strings. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass ZipRecruiter's OA.

ZipRecruiter reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Add Two Numeric Strings with Carry FAQ

How hard is the ZipRecruiter add two numeric strings question really?+

It's easy on paper, and the difficulty is all in the edges. The algorithm is grade-school addition. People lose points on the final carry, unequal lengths, and converting chars to digits. If you write the loop condition correctly, the rest falls into place in about ten lines.

What's the trick to getting the carry right?+

Loop while i >= 0 or j >= 0 or carry > 0. That one condition covers different lengths and the extra leading digit in cases like 999 + 1. Treat a missing digit as 0 and you never need special-case code after the loop.

Can I just convert the strings to integers and add them?+

No. The statement says the inputs may be too large for fixed-width types, and lengths go up to 10000 digits. Some languages have big integers, but the problem explicitly asks for digit-by-digit addition with carry, so do it manually.

What's the time and space complexity I should state?+

Time is O(max(n, m)) since you touch each digit once. Space is O(max(n, m)) for the output. Append digits to a list and reverse once at the end instead of prepending, which would cost O(n^2) on long inputs.

How do I prepare for this in 48 hours?+

Write it from scratch twice, then test 999 + 1, 0 + 0, and a short string plus a long one like 5 + 99995. Those cover the carry and length edges. Then move on, since this pattern is a warm-up and the other OA questions likely need your time more.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with ZipRecruiter.

OA at ZipRecruiter?
Invisible during screen share
Get it