Concatenate Digit-wise Sums
Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that trips people in this ZipRecruiter OA, reported in October 2023, is the sum 18 contributing two characters and nothing carrying over. It looks like "add two big numbers" and it isn't. It's a right-aligned, digit-by-digit math problem where each position stands alone. If you've got the OA coming in a day or two, you need the shape of the solution now. Two pointers from the right, build pieces, reverse at the end. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is simple enough that you should walk in ready.
The problem
For this exercise, use the callable contract below. You are given two non-empty strings a and b consisting of decimal digits. Right-align the strings. For each aligned position, add the corresponding digits. If one string has no digit at that position, use the digit from the other string as the sum for that position. Return a string formed by concatenating these per-position sums from the leftmost aligned position to the rightmost. A sum such as 18 contributes both characters 1 and 8; there is no carry between positions. Function concatenateDigitSums(a: String, b: String) → String Examples Example 1 a = "99" b = "99" return = "1818" The two aligned positions each contain 9 + 9 = 18. Concatenating the two sums gives "1818". Example 2 a = "11" b = "9" return = "110" The leftmost position contains only 1, and the rightmost position has 1 + 9 = 10. Concatenating 1 and 10 gives "110". Constraints 1 <= a.length, b.length <= 105 a and b contain only decimal digits and each represents a positive integer. Digits are aligned from the right, and every position is summed independently without carrying.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that this is LeetCode's Add Strings with the carry deleted. Walk two indexes from the end of both strings. At each step, take the digit from a if the index is valid, else 0, and do the same for b. That gives the right answer even when one string is missing a digit, since adding 0 returns the other digit. Convert the sum to a string and push it onto a list. Because you're moving right to left, reverse the list of pieces before joining. Don't reverse each piece, or 18 becomes 81. The common pitfall is string concatenation in a loop on inputs up to 10^5, which turns quadratic in some languages. Collect pieces in an array and join once. If your head goes blank under the timer, StealthCoder can hand you the pointer loop in real time, but the logic is about ten lines.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Concatenate Digit-wise Sums 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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass ZipRecruiter's OA.
ZipRecruiter reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Concatenate Digit-wise Sums FAQ
How hard is Concatenate Digit-wise Sums really?+
Easy. It's a two-pointer string walk with no carry logic. The only real traps are reversing the order correctly and not reversing the multi-digit sums like 18. If you've done Add Strings before, you can finish it in a few minutes.
What's the trick to getting it right?+
Iterate from the right end of both strings with two indexes. Treat a missing digit as 0, add, convert the sum to a string, and store it. After the loop, reverse the list of pieces and join them. Keep each sum's characters in their original order.
Why does example 2 return 110 and not 20?+
Because there's no carry and sums are concatenated. The right position is 1 + 9 = 10. The left position only has the 1 from a, so it contributes 1. Reading left to right gives 1 then 10, which is 110.
Will string concatenation be too slow at 10^5 length?+
It can be in languages where strings are immutable and appending copies. Push each sum onto an array or string builder, then reverse and join once at the end. That keeps the whole solution linear in the input size.
How do I prepare for this in 48 hours?+
Solve Add Strings first, then modify it by removing carry and appending the full sum string. Test with equal lengths, unequal lengths, and all 9s. Check that your output order is leftmost to rightmost. That covers nearly every edge case here.