126. Jump Game II (Minimum Jumps)

HardArrayArray

Given an array where nums[i] is the maximum jump length from position i, return the minimum number of jumps to reach the last index. You can assume you can always reach the last index.

Input: An integer array.

Output: Integer — minimum jumps.

Examples

Example 1
Input: [2,3,1,1,4]
Output: 2
Explanation: Jump 0->1->4.
Example 2
Input: [2,3,0,1,4]
Output: 2
Explanation: Jump 0->1->4.
Example 3
Input: [1]
Output: 0
Explanation: Already at end.

Constraints

Asked by

AmazonMicrosoftBloombergGoogleFlipkartIBM
Solve this problem in the editor →