Skip to content
BASA DSA

Jump Game II

MediumGreedy

Starting at index zero, nums[i] is your maximum forward jump length from i. Return the fewest jumps needed to reach the final index.

Example 1

Input
nums = [2,3,1,1,4]
Output
2

Explanation

Jump 0->1->4; two jumps suffice and one does not.

Example 2

Input
nums = [1,1,1]
Output
2

Explanation

One-step limits require two jumps to reach index 2.

Example 3

Input
nums = [0]
Output
0

Explanation

Start already equals finish, requiring no jumps.

Constraints

  • 1 <= len(nums) <= 10000
  • Values are 0..1000
  • The final index is reachable

Function contractjumpArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…