mediumGreedyAmazonGoogle
Last-Tile Reacher
A platformer character on tile 0 jumps up to nums[i] tiles from tile i. Can they reach the last tile?
Given a non-negative array nums where nums[i] is the max jump length from index i, determine if you can reach the last index starting from index 0.
Choose approach
2
0i
3
11
2reach
1
34
41/6
Narrationstep 1 of 6
i=0: reach = max(2, 0+2) = 2.
Variables
i=0
reach=2
How to think about it
- Only need to know farthest reachable index so far.
- Zero jump length blocks progress unless already past it.
Edge cases to catch in interview
- Single element -> true.
- Zero in path with insufficient prior reach -> false.
Examples
Example 1
false{"values":[3,2,1,0,4]}
Try your own input
SpacePlay / pause
← / →Previous / next step
RReset to start
. or >Cycle speed