Reported February 2022
ZipRecruitermath

Single-Digit Addition Equation Repairs

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 sneaky part of this ZipRecruiter question, reported in February 2022, is an equation that's already correct. Example 2 returns 0 because you must change exactly one digit to a different one, so a valid starting state doesn't count for free. A naive solution counts the original match or allows zero as a replacement digit, and both give wrong answers. Example 1 shows the zero rule too: changing b to 0 is banned. It's a math and enumeration problem dressed up as a string one. If you blank mid-assessment, StealthCoder runs invisibly on screen and can hand you the enumeration approach. The approach itself is short once you see it.

The problem

a, b, and c are positive decimal strings containing no zero digits. Change exactly one digit in exactly one input to a different digit from 1 through 9.
Count substitutions after which a + b = c.

Function
countEquationRepairs(a: String, b: String, c: String) → int

Examples
Example 1
a = "7"
b = "1"
c = "7"
return = 2
Changing b to 0 is forbidden; the two valid nonzero repairs satisfy the equation.
Example 2
a = "1"
b = "1"
c = "2"
return = 0
The equation is already true, but exactly one different digit must be changed.

Constraints
1 <= a.length,b.length,c.length <= 15

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is that the search space is tiny. Each string has at most 15 digits, so there are at most 45 positions, and each position has 8 replacement digits from 1 through 9 excluding the current one. That's at most 360 candidates. For each, build the modified strings, parse them to 64-bit integers, and check a + b == c. Fifteen digits stays under 10^15, so a long holds the values and the sum with no overflow. Count each (string, position, new digit) triple once. The pitfalls are all about the rules. Skip any replacement equal to the original digit, which keeps the already-true case from scoring. Never try 0. Don't dedupe by resulting equation, since different substitutions each count. Keep the loop clean and the problem is mostly bookkeeping. If the assessment clock gets loud and you freeze, StealthCoder is the safety net that surfaces this enumeration while you stay in control.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Single-Digit Addition Equation Repairs 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. If you're reading this with an OA window open, you're who this was built for.

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. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Single-Digit Addition Equation Repairs FAQ

How hard is the Single-Digit Addition Equation Repairs problem really?+

Easy to medium. The logic is brute force over at most 360 substitutions. The difficulty is reading the rules correctly: exactly one change, a different digit, digits 1 through 9 only. Most failed attempts come from missing one of those constraints, not from the algorithm.

What's the trick to solving it?+

Enumerate every position in a, b and c, try each digit 1 through 9 that differs from the current one, then test a + b == c with integers. The input is small enough that no clever carry logic is needed. Simple and correct beats optimized here.

Why does Example 2 return 0 when 1 + 1 = 2 already holds?+

Because the change is mandatory. You must alter exactly one digit to a different one, and any such change from 1 + 1 = 2 breaks the equation. So no valid substitution exists. Don't add a bonus count for the original state.

Do I need big integers for 15-digit strings?+

No. A 15-digit number is below 10^15, and a 64-bit signed integer holds about 9.2 * 10^18. Adding two of them is safe. In languages with 32-bit ints by default, use long explicitly so parsing doesn't overflow.

How do I prepare for this in 48 hours?+

Practice writing a clean enumerate-and-check loop that mutates one character at a time and restores it. Test on both examples, plus a case where the digit would be zero. Then check off-by-one on string indexes and the skip-same-digit rule. That covers nearly every failure mode.

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