Typorithm · medium

Jump Game

▷ Interactive algorithm labjump-gamegreedyreachabilityfarthest-reachgreedy-choice
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Jump Game

0%

Greedy

Walk left to right, tracking the farthest reachable index; fail the moment an index is unreachable.

Each value tells you the maximum jump length from that index.

The greedy insight is that only the farthest reach matters, not which exact jumps you take.

If you ever stand on an index beyond the farthest reach, the last index is impossible.

Preparing algorithm lab…
01

Track one number: the farthest reach.

02

Fail if i passes reach.

03

reach = max(reach, i + nums[i]).

function canJump(nums) {
  let reach = 0;

  for (let i = 0; i < nums.length; i += 1) {
    if (i > reach) {
      return false;
    }
    reach = Math.max(reach, i + nums[i]);
  }

  return true;
}

Read the implementation

Connect each part of the code to the concept before you type.

1. Farthest reach

Track the farthest index reachable so far.

let reach = 0

2. Scan indexes

Walk every index from left to right.

for (let i = 0; i < nums.length; i += 1)

3. Unreachable

If the current index is past the farthest reach, it can never be reached.

if (i > reach)

4. Extend reach

From index i you can reach i + nums[i]; keep the farthest.

reach = Math.max(reach, i + nums[i])

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Jump Game: Visual Walkthrough & Practice · Typorithm | ApplyDjinn