Reported October 2022
ZipRecruitermath

Alternating Signed Digit Sum

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 classic way to fumble this ZipRecruiter OA, reported in October 2022, is to treat the string like numbers instead of characters. The task looks tiny: walk a digit string, add at even positions, subtract at odd ones. It's a math and string warm-up, and the sign rule is the entire problem. People lose points converting wrong, flipping the sign convention, or overthinking a one-pass loop. If you blank on the setup, StealthCoder runs invisibly during the live assessment and hands you the loop. You probably won't need it, but it's a cheap hedge.

The problem

You are given a nonempty decimal string digits. Read it from left to right using zero-based positions.
Add digits at even positions and subtract digits at odd positions. Return the resulting signed sum.

Function
alternatingDigitSum(digits: String) → int

Examples
Example 1
digits = "521"
return = 4
The result is 5 - 2 + 1 = 4.
Example 2
digits = "12345"
return = 3
The result is 1 - 2 + 3 - 4 + 5 = 3.

Constraints
1 <= digits.length <= 100000
digits contains only decimal digits.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is one pass with an index. For each position i, convert the character to its digit value with ord(c) - ord('0'), then add it if i is even and subtract it if i is odd. That's O(n) time and O(1) space, which easily handles a length of 100000. The common pitfall is the sign. Position zero is positive, so "521" gives 5 - 2 + 1 = 4, not the reverse. Another slip is adding the raw character code, which gives a huge wrong number. Don't parse the whole string into an integer either. Check your loop against "12345", which should return 3. If your mind goes blank under the timer, StealthCoder is the safety net that surfaces the loop while you stay in the assessment. Test a single-digit input too, since the answer is just that digit.

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 Alternating Signed Digit Sum 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.

Alternating Signed Digit Sum FAQ

How hard is the Alternating Signed Digit Sum question really?+

It's easy. One loop, one running total, and a sign that flips by position parity. The ZipRecruiter version from October 2022 has no hidden edge cases beyond converting characters to digits correctly. Spend your time on clean code and a quick check against both examples.

What's the trick to solving it?+

Use the index parity. Even index adds the digit, odd index subtracts it. Convert each character with ord(c) - ord('0') or your language's equivalent. You don't need a separate sign variable, though a toggling sign works just as well.

What's the most common mistake?+

Flipping the sign convention or adding character codes instead of digit values. Position zero is positive. For "521" the answer is 4. If you get -4, your signs are backwards. If you get something huge, you forgot the character conversion.

Will large inputs cause overflow problems?+

No. The length is at most 100000 and each digit is at most 9, so the sum stays under about 900000 in magnitude. A standard int is fine. Just avoid converting the full string into a number, which would overflow.

How do I prepare for this in 48 hours?+

Write the loop once from memory and run it on "521" and "12345". Then try a one-digit string. After that, move on to other string and math basics, since problems like this are warm-ups that reward speed and accuracy more than cleverness.

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