LeetCode 45 Jump Game II - Problem Statement

The problem

Given an array where nums[i] is the maximum jump length from position i, find the minimum number of jumps to reach the last index.

You can always reach the last index.

With nums = [2,3,1,1,4]:

  • Jump 1: position 0 → position 1 (jump length 1, could go to 2).
  • Jump 2: position 1 → position 4 (jump length 3).
  • Minimum: 22 jumps.

With nums = [2,3,0,1,4]:

  • Jump 1: 0 → 1.
  • Jump 2: 1 → 4.
  • Minimum: 22 jumps.

Constraints: 11 \le nums.length 104\le 10^4.