Find the minimum number of jumps needed to reach the last index of an array.
You are given an integer array nums where nums[i] represents the maximum distance you can jump forward from index i.
Start at index 0. In one move, you may jump from index i to any index j such that i < j <= i + nums[i].
Return the minimum number of jumps required to reach the last index of the array.
nums of length n.nums[i] is the maximum forward jump length from index i.n - 1.1 <= nnums.length = nExample 1
Input
nums = [2,3,1,1,4]
Output
2
Explanation
Jump from index 0 to index 1, then from index 1 to index 4.
Example 2
Input
nums = [2,3,0,1,4]
Output
2
Explanation
One optimal path is 0 -> 1 -> 4.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.