Medium

Quiz

#45 Jump Game II

APPROACH

Starting at index 0 of the 0-indexed array nums, where nums[i] is the maximum forward jump length from index i, return the minimum number of jumps to reach the last index. It is guaranteed a valid path always exists.

Example 1:

Input: nums = [2,3,1,1,4]
Output: 2
Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.

Example 2:

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

What is the optimal approach for this problem?