Minimum Jumps to Reach Home
Reported by candidates from GoodScore's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The GoodScore OA reported in September 2026 hides its trap in one rule: you can't jump backward twice in a row. Miss that and your BFS looks right, passes the first example, then fails hidden cases. This is Minimum Jumps to Reach Home, a shortest-path-on-implicit-graph problem. Positions are nodes, jumps are edges, and every edge costs one. If you've got an OA invite and 48 hours, learn the state definition and the upper bound on positions. StealthCoder is the hedge if you blank on the live OA, but the core idea fits in your head.
The problem
Start at position 0. A forward jump adds forward; a backward jump subtracts backward. Positions cannot become negative, forbidden positions cannot be visited, and two backward jumps cannot occur consecutively. Return the minimum jumps needed to reach target, or -1 if it is unreachable. Function minimumJumps(forbidden: int[], forward: int, backward: int, target: int) → int Examples Example 1 forbidden = [14,4,18,1,15] forward = 3 backward = 15 target = 9 return = 3 Case 1 exercises the documented deterministic contract. Example 2 forbidden = [8,3,16,6,12,20] forward = 15 backward = 13 target = 11 return = -1 Case 2 exercises the documented deterministic contract. Example 3 forbidden = [1,6,2,14,5,17,4] forward = 16 backward = 9 target = 7 return = 2 Case 3 exercises the documented deterministic contract. Constraints 0 <= forbidden.length <= 2000. 1 <= forward, backward, target <= 2000. 1 <= forbidden[i] <= 2000, with unique forbidden positions.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Run BFS, but the node isn't just the position. It's (position, lastMoveWasBackward). Track visited on that pair, because reaching position 5 after a backward jump allows different moves than reaching it after a forward jump. Using position alone is the classic bug, and it gives wrong answers or -1 when a path exists. The second trap is bounding the search. Positions can't go negative, and going far past target plus the jump sizes is pointless. A common safe cap is around max(forbidden max, target) + forward + backward, or roughly 6000 given the constraints. Forward moves go to pos + forward if it's under the cap and not forbidden. Backward moves go to pos - backward if it's at least 0, not forbidden, and the last move wasn't backward. First time you pop target, return the level count. If the queue empties, return -1. StealthCoder is the safety net if the state design slips under pressure.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum Jumps to Reach Home 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass GoodScore's OA.
GoodScore 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.
Minimum Jumps to Reach Home FAQ
What's the trick in Minimum Jumps to Reach Home?+
Put the last move type into the BFS state. Visited is keyed by position and whether you just jumped backward. Without that, you either block valid paths or allow illegal double-backward jumps. Everything else is standard shortest-path BFS with unit edge cost.
How do I bound the search so BFS terminates?+
Cap positions at something like max(target, max forbidden) + forward + backward, around 6000 with these constraints. Going beyond that can't help, since you could never usefully come back. Also reject negative positions and forbidden cells. The visited set then guarantees termination.
Why does a plain position-only visited set fail?+
Arriving at a cell by a backward jump forbids another backward jump from there. Arriving by a forward jump allows both. Those are different states with different futures. Marking the cell visited after the first arrival can hide the only valid route to the target.
Is this a graph problem or dynamic programming?+
Treat it as a graph. Each state has at most two outgoing edges, all with cost one, so BFS gives the minimum jumps directly. DP over positions is awkward because moves go both directions and create cycles. BFS handles cycles cleanly through visited.
How should I prepare in 48 hours for this GoodScore question?+
Write BFS with a (position, flag) state from scratch twice. Test the three given examples, then a case where target is unreachable and one where forward is larger than the cap would allow. Check that the target at position 0 isn't possible since target is at least 1. Aim for clean, short code.