Given an array nums where nums[i] represents the maximum jump length from index i, return the minimum number of jumps needed to reach the last index. You can assume the last index is always reachable. Pattern focus: Jump Game. Track the current jump range and the farthest point reachable with one additional jump, then extend the range when you finish the current one.
nums = maximum jump lengths at each index
minimum number of jumps to reach the last index
Example 1:
Input:
nums = [2,3,1,1,4]
Output:
2
Explanation:
Jump from index 0 to index 1, then to the last index.
Example 2:
Input:
nums = [2,3,0,1,4]
Output:
2
Explanation:
A minimum of two jumps is enough: 0 -> 1 -> 4.
Example 3:
Input:
nums = [1,1,1,1]
Output:
3
Explanation:
You must move one step at a time.