MediumGreedy · Dynamic Programming · Arrays

Jump Game

Each nums[i] is the maximum jump length from index i. Starting at index 0, return true if you can reach the last index, otherwise false.

nums = [1,2,0,1,0] → true (0 → 1 → 3 → 4)nums = [1,2,1,0,1] → false

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

The array

Arcs = possible jumps; the mark under each cell says whether it can reach the end

Time and space complexity

n = len(nums). The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Integers from 0 to 99; drawings use at most 10 numbers for top-down DP, 12 for bottom-up DP and 14 for greedy.