GreedyAnimated
Jump Game
Track the furthest reachable index.
Time
O(n)
Extra space
O(1)
Use it for
Reachability with variable jumps.
How it works
- Each number is the farthest you may jump from that index.
- Keep one number: the farthest index you can reach so far.
- Walk left to right. If you stand on an index beyond that reach, you are stuck.
- Otherwise extend the reach with i + a[i]. If it covers the last index, you win. O(n), no table needed.
Watch it run
Loading animation…