mediumGreedyAmazon
Minimum Hops
The platformer finds the FEWEST jumps to clear the stage, given per-tile max jump distances.
Given a jump-length array, return the minimum number of jumps to reach the last index (assume reachable).
Choose approach
2
0i
3
11
2endfar
1
34
41/5
Narrationstep 1 of 5
i=0: farthest=2, jumps=1, end=2.
Variables
i=0
farthest=2
jumps=1
end=2
How to think about it
- Each 'jump' consumes a frontier.
- Greedy = always jump to the farthest-reaching option.
Edge cases to catch in interview
- Length 1 -> 0.
- Length 2 with nums[0] ≥ 1 -> 1.
Examples
Example 1
2{"values":[2,3,0,1,4]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed