Skip to content
StackDecode
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

  1. Each number is the farthest you may jump from that index.
  2. Keep one number: the farthest index you can reach so far.
  3. Walk left to right. If you stand on an index beyond that reach, you are stuck.
  4. 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…