Reported February 2024
ZipRecruitermath

Count Distinct Swappable Digit Pairs

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

You've got a ZipRecruiter OA incoming with a digit-swapping problem. This one landed in February 2024 and it's asking you to count distinct pairs of digits that can be swapped in a number while keeping the result valid. The pattern is pure math, not a data structure trap. You need to understand which swaps actually matter and which are duplicates. StealthCoder will spot the formula if you freeze mid-problem.

Pattern and pitfall

The trick here is recognizing that you're not iterating through all possible swaps. You're counting distinct pairs. The math angle means you need to figure out: how many unique digit positions can form valid swap pairs, and do swaps of identical digits count once or twice. Most candidates burn time simulating every swap instead of deriving a formula. The pitfall is overcounting when a number has repeated digits, or undercounting when you miss the constraint about what makes a swap 'valid' or 'distinct'. The problem forces you to think combinatorially, not just recursively. If you blank on the formula during the live OA, StealthCoder will feed you the counting logic to avoid the brute-force timeout.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Count Distinct Swappable Digit Pairs 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Distinct Swappable Digit Pairs FAQ

Is this about permutations or just counting pairs?+

It's counting. You're not generating permutations of the number. You're finding how many distinct pairs of digit positions can swap without violating some constraint, usually that the result is a valid number (no leading zeros, or stays within a range). Think combination math, not iteration.

Do swaps of the same digit count?+

Likely not, or they count once. If a number has multiple 3s, swapping one 3 with another 3 doesn't change the number, so it probably doesn't count as a distinct swap. Read the problem carefully for whether identical digits are excluded.

What's the constraint that makes this hard?+

Usually leading zeros. If you swap the first digit with a 0, the result is invalid. You also might have a range constraint, like the swapped number must stay below a threshold. That kills many naive pairs and forces you to filter, not just count n choose 2.

Can I solve this without deriving a formula?+

You could brute force by checking every pair of positions, but that risks TLE on large numbers with many digits. The math path is faster: figure out how many valid pairs exist algebraically, then add edge cases. Formulas beat loops here.

How do I prepare for this in 48 hours?+

Drill the math: review combinations and counting problems. Work through one or two digit-swapping problems on paper to spot the pattern. Understand what makes a swap valid or invalid in your context. Then during the OA, write down your counting logic before coding.

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