Alternating Direction Jump Game
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks most first attempts at the Alternating Direction Jump Game is treating the array as read-only. It isn't. Every jump bumps the value at the spot you just left, so the board changes under you. Google's OA, reported in September 2026, is pure simulation on an array of at most 12 elements, which sounds easy until the infinite-loop case shows up. Example 2 returns -1, and a naive while loop just hangs. This page gives you the pattern and the traps before your invite clock runs out. StealthCoder runs invisibly during the live OA as a safety net if you blank on the termination rule.
The problem
You are given an integer array values, a starting index start, and a positive integer increment. The first move is odd. On an odd move, scan left from the current index and jump to the nearest index whose value is exactly the current value plus 1. On an even move, scan right and use the same target-value rule. After a successful jump, add increment to the value at the position you just left, then alternate the move parity. If no valid jump exists, return the current index. If play continues forever, return -1. Function playJumpGame(values: int[], start: int, increment: int) → int Examples Example 1 values = [3,4,2,2,7] start = 2 increment = 4 return = 1 The odd move reaches index 0, the even move reaches index 1, and no value 5 exists to its left. Example 2 values = [2,1] start = 1 increment = 2 return = -1 The two positions alternate forever while their values rise together. Constraints 1 <= values.length <= 12. -100 <= values[i] <= 100. 0 <= start < values.length. 1 <= increment <= 20.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The core is a straightforward loop. Track the current index and a move counter. On odd moves scan left for the nearest index holding current value plus 1, on even moves scan right. If you find one, add increment to the value at the index you left, then jump and flip parity. If you find none, return the current index. The pitfall is the -1 case. Because values keep changing, a visited set of (index, parity) is wrong, since the same position can be revisited with different values. In Example 2 the two values just climb together forever. You need a real stopping rule, and a generous step cap is the practical option at this size. Also update the old cell before moving, and read the current value fresh each step. If you freeze on the loop detection mid-assessment, StealthCoder is the hedge that surfaces a working structure while you keep your hands moving.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Alternating Direction Jump 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. 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google 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.
Alternating Direction Jump Game FAQ
How hard is the Alternating Direction Jump Game really?+
The logic is easy and the edge cases are not. Scanning left or right and updating a cell is a few lines. The difficulty is deciding when play is infinite. With an array of at most 12, it's a medium-feeling simulation that punishes sloppy state handling.
What's the trick to detecting the -1 case?+
Don't rely on a visited set of (index, parity), because values mutate and states don't repeat exactly. Use a step cap or a reasoned repeat check. Example 2 is your test: values [2,1], start 1, must return -1 instead of hanging.
Do I scan from the current index or the array edge?+
From the current index, outward in the move direction, and take the nearest match. On an odd move walk left from index minus 1. On an even move walk right from index plus 1. Scanning from the edge returns the wrong target when duplicates exist, like the two 2s in Example 1.
When exactly does the increment get applied?+
After a successful jump, to the position you just left, not the one you land on. Then parity flips. If no jump exists you return the current index and nothing changes. Mixing up which cell gets the increment is the most common wrong answer on Example 1.
How do I prepare in 48 hours for this Google OA?+
Write the simulation loop from scratch twice and hand-trace both examples. Then test edge cases: length 1, a start with no valid first jump, and negative values. Practice explaining your termination rule, since that's the part most people get wrong under pressure.