107. Jump Game II
Medium · Array
You are given an array of non-negative integers. Each element is the maximum distance you can jump forward from that index. You start at index 0, and it is always possible to reach the last index.
Return the minimum number of jumps needed to reach the last index.
The input is the array of jump lengths. Return a single integer — the minimum jump count (0 if the array has one element).
Examples
Example 1 Input: [2,3,1,1,4] Output: 2 Explanation: Jump 1 step to index 1, then 3 steps to the last index.
Example 2 Input: [2,3,0,1,4] Output: 2 Explanation: Index 0 → index 1, then index 1 → the end.
Constraints
- Standard input/output constraints apply