Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Jump Game II
Bookmark
Dynamic Programming
BFS / Greedy
Input
Example 1
With zero
All ones
Single element
Large first jump
Increasing
Custom
nums
=
[2, 3, 1, 1, 4]
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
∞
∞
∞
∞
i
compute dp[
1
] from every earlier index that reaches it
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
∞
∞
∞
i
compute dp[
2
] from every earlier index that reaches it
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
1
∞
∞
i
j
dp[
0
] + 1 =
1
→ dp[
2
] =
1
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
1
∞
∞
i
compute dp[
3
] from every earlier index that reaches it
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
1
2
∞
i
j
dp[
1
] + 1 =
2
→ dp[
3
] =
2
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
1
2
∞
i
compute dp[
4
] from every earlier index that reaches it
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
1
2
∞
i
j
0
+
2
=
2
<
4
→ cannot reach the target
nums
jump len
dp
min jumps
0
1
2
3
4
2
3
1
1
4
0
1
1
2
2
i
j
2
+
1
=
3
<
4
→ cannot reach the target
nums
jump len
dp
min jumps
0
1
2
3
4
1
2
2
3
1
1
4
0
1
1
2
2
Minimum jumps =
2
algo
master
.
io
Step:
Start: Find minimum jumps to reach the last index
0 / 16
Input
Example 1
With zero
All ones
Single element
Large first jump
Increasing
Custom
nums
=
[2, 3, 1, 1, 4]
0 / 16
algo
master
.
io
Step:
Start: Find minimum jumps to reach the last index