Skip to content
Decoder

Jump Game II

Medium

Problem

Same board as Jump Game: from index i you may jump forward up to nums[i] places. This time the last index is always reachable. Return the fewest jumps needed to get there from index 0.

Example 1

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

Example 2

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

Example 3

Input
nums = [0]
Output
0
Why
already there

Constraints

  • 1 <= nums.length <= 10^4
  • 0 <= nums[i] <= 1000
  • The last index can always be reached.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.