Jump Game II

Greedy & Intervals, problem 4 of 8

Jump Game II

Medium

LC #45

greedybfsarray

Not attempted yet

You start at index 0 of nums. From index i you may jump forward up to nums[i] steps. The last index is always reachable.

Return the minimum number of jumps to reach the last index.

Example 1

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

Jump to index 1, then 3 steps to the end.

Example 2

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

Example 3

Input: nums = [0]
Output: 0

Constraints

  • 1 <= nums.length <= 10^5
  • 0 <= nums[i] <= 1000
  • The last index is reachable

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.