Workspace Jump Game
0d
DSA Problem Sheet

Jump Game

Each entry is the maximum forward jump from that position. Return 1 if the final position is reachable from index zero, otherwise 0.

EXECUTION LAB

Each entry is the maximum forward jump from that position. Return 1 if the final position is reachable from index zero, otherwise 0.

Input and constraints
  • Supply at least one value.
  • Each value must be nonnegative.
  • Use at most 32 integers. Each numeric input is between -1000 and 1000.

Code inspector

def solve(values, target):
reach = 0
i = 0
while (i < len(values)):
if (i > reach):
return 0
reach = max(reach, (i + values[i]))
i = (i + 1)
return 1

Visualizer

Step 1 of 6
02i, reach
13
21
31
44

Inspect the current state

Verify that position 0 lies within the frontier 0.

Variable watch

i 0reach 0

Step explanation

Verify that position 0 lies within the frontier 0.

comparisons 1reads 0writes 0swaps 0recursiveCalls 0
Educational simulation · O(n) time · O(1) space

Worked explanation

A row of relay stations extends a signal only when the signal reaches the station.

Guided solution

Keep the furthest position reachable by processing only positions already reachable.

O(n) time · O(1) auxiliary space

Examples

Worked example · {"values":[2,3,1,1,4],"target":0} ⇒ 1

Edge case 1 · {"values":[1,0,2],"target":0} ⇒ 0

Edge case 2 · {"values":[0],"target":0} ⇒ 1

Progressive hints

Hint 1A row of relay stations extends a signal only when the signal reaches the station.
Hint 2Keep the furthest position reachable by processing only positions already reachable.
Hint 3Step through the worked example and inspect the highlighted variables before each update.

Common mistake

Using jump lengths from unreachable positions can create a fictitious route.

Interview follow-up

Why is every index up to the frontier reachable?