Reported November 2021
ZipRecruitermath

Add Numbers Stored in Four-Digit Chunks

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 first line of this ZipRecruiter OA, reported in November 2021, is about the data structure: arrays of base-10000 chunks, most significant first. That's a big-number addition problem in disguise. If you've ever added two linked-list numbers, you've done this. The catch is that the arrays are aligned from the wrong end and have different lengths. It's a math and array problem, not a clever one, and the points go to whoever handles the edges cleanly. If you blank on the carry logic during the live assessment, StealthCoder runs invisibly as a safety net and hands you the loop.

The problem

Each array represents one nonnegative integer as base-10000 chunks in most-significant-first order. Every chunk is between 0 and 9999; conceptual leading zeroes inside a chunk are allowed.
Add the represented numbers and return normalized base-10000 chunks in the same order. Return [0] for zero and omit other leading zero chunks.

Function
addChunkedNumbers(first: int[], second: int[]) → int[]

Examples
Example 1
first = [1,9999]
second = [2]
return = [2,1]
9999 plus 2 produces a carry into the preceding chunk.
Example 2
first = [12,34]
second = [5,6,7]
return = [5,18,41]
Missing high chunks are treated as zero.

Constraints
1 <= first.length, second.length <= 100000
0 <= chunk < 10000

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to add from the end, like paper addition. Put one pointer at the last index of each array and walk backward. At each step, sum the two chunks (treat a missing chunk as 0) plus the carry. The new chunk is sum % 10000 and the new carry is sum / 10000. Keep looping while either array has chunks left or the carry is nonzero. You build the result in reverse, so reverse it at the end. Example 1 shows why: 9999 + 2 gives 10001, so the chunk is 1 and the carry is 1, which becomes the leading 1. The pitfalls are the final carry, mismatched lengths, and leading zero chunks. Inputs can have leading zero chunks like [0,0,5], so strip them and return [0] if nothing is left. With 100000 chunks per array, linear time is required. StealthCoder is your hedge if the index handling falls apart under the clock.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Add Numbers Stored in Four-Digit Chunks 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

ZipRecruiter reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Add Numbers Stored in Four-Digit Chunks FAQ

How hard is the ZipRecruiter chunked addition problem really?+

Easy to medium. There's no hidden algorithm, just grade-school addition in base 10000. Most failures come from edge cases: unequal lengths, a leftover carry at the end, and leading zero chunks in the input or output. Write it cleanly and it takes about fifteen minutes.

What's the trick to solving it?+

Iterate from the last index of both arrays backward. Add the two chunks plus the carry, push sum % 10000, and carry sum / 10000. Continue until both arrays are exhausted and the carry is zero. Then reverse the result so it's most-significant-first again.

What edge cases should I test before submitting?+

Test [0] plus [0], which must return [0]. Test a carry that creates a new leading chunk, like [9999] plus [1]. Test very different lengths, like the second example. Also test inputs with leading zero chunks, since the output must strip them.

Will this overflow or time out on 100000 chunks?+

Not if you stay linear. Each step sums two values under 10000 plus a carry of at most 1, so it fits easily in a 32-bit int. Don't convert to a giant integer or string and back. A single backward pass over both arrays is enough.

How do I prepare for this in 48 hours?+

Practice two or three carry-based problems: add two linked-list numbers, add strings, and add binary. They all share the same loop shape. Then write this one from scratch once, including the leading zero strip. That's enough for this OA.

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