Frog Jump
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A frog wants to cross a river by hopping across a series of stones. The stones sit at strictly increasing positions along the river, given by the sorted array stones, where stones[i] is the coordinate of the i-th stone. The frog begins on the first stone (stones[0], which is always at position 0).
The frog's jumps follow one rule about momentum: if the frog's previous jump covered a distance of k units, then its next jump must cover a distance of k - 1, k, or k + 1 units. Every jump must land exactly on a stone (the frog cannot land in the water), and the frog can only move forward (the jump distance must be positive).
The frog's very first jump must be exactly 1 unit, taking it from the stone at position 0 toward the stone at position 1 (if such a stone exists).
Return true if the frog can reach the last stone (stones[stones.length - 1]), otherwise return false.
The key challenge is that the state of the frog is not just its position but also the size of the jump it just made, since that determines which jumps are legal next. Because positions can be far apart and arbitrary, a hash structure mapping positions to stones (or memoizing (position, jumpSize) pairs) is used to drive the search efficiently.
Examples
Constraints
- `2 <= stones.length <= 2000`
- `0 <= stones[i] <= 2^31 - 1`
- `stones[0] == 0`
- `stones` is sorted in strictly increasing order.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.