Reported October 2023
ZipRecruiterstack

Adjacent Equal-Pair Removal Game

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

A stack is the whole solution to this ZipRecruiter OA, reported in October 2023. The game looks like it needs minimax, but it doesn't. Alice and Bob remove adjacent equal pairs from a string, and whoever can't move loses. You've got a string up to 100000 characters and a function called pairRemovalWinner. The trick is that the total number of moves is fixed no matter how anyone plays. Once you see that, the code is ten lines. If you blank on the live assessment, StealthCoder is the invisible safety net that reads the problem and hands you the stack approach.

The problem

Alice and Bob play a game on a string values. Alice moves first. On each move, remove any adjacent equal pair; the remaining characters close together.
A player who cannot move loses. Return "Alice" or "Bob" assuming optimal play.

Function
pairRemovalWinner(values: String) → String

Examples
Example 1
values = "aa"
return = "Alice"
Alice removes the only pair, leaving Bob without a move.
Example 2
values = "abba"
return = "Bob"
Two cancellations occur, so Bob makes the final move.

Constraints
0 <= values.length <= 100000
values contains lowercase English letters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Here's the trick. Reduce the string with a stack: push each character, and if it matches the top, pop and count one removal. The final reduced string is the same no matter what order pairs get removed, so the total number of moves is fixed. That kills the need for game search. If the count is odd, Alice makes the last move and wins. If it's even, Bob wins. Check it against the examples: "aa" gives one removal, so Alice. "abba" gives two, so Bob. The common pitfall is writing recursion or DP over substrings, which times out at 100000 characters. Another miss is the empty string, which has zero moves, so Alice can't move and Bob wins. Runs in O(n) time and O(n) space. If the parity insight slips away mid-assessment, StealthCoder can surface it live without the proctor seeing anything.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Adjacent Equal-Pair Removal Game 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 would have shipped this the night before his JPMorgan OA if he'd had it.

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. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Adjacent Equal-Pair Removal Game FAQ

What's the trick in the Adjacent Equal-Pair Removal Game?+

The number of total moves is invariant. Reduce the string with a stack, counting each pop as one removal. Order of removals doesn't change the final result or the count. So you skip game theory entirely and just check whether the count is odd or even.

Who wins, Alice or Bob, based on the count?+

Odd count means Alice wins, since she moves first and takes the last move. Even count means Bob wins. Zero removals is even, so an empty string or one with no adjacent pairs returns Bob, because Alice can't move at all.

How hard is this ZipRecruiter OA problem really?+

Easy once you spot the stack and the parity idea. It's disguised as a game, which scares people into minimax. The implementation is short. The difficulty is purely recognizing that optimal play doesn't matter here.

Will a brute force approach pass?+

No. Trying every removal order is exponential, and even repeated string scanning with replace is O(n^2) in the worst case. With length up to 100000, you need the single-pass stack solution at O(n).

How do I prepare for this in 48 hours?+

Write the stack reduction once from scratch, like removing adjacent duplicates. Then practice the parity argument: if moves are forced in count, the winner depends only on odd or even. Test on "aa", "abba", an empty string, and a string with no pairs.

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