A frog stands on the first stone of a row. The array nums tells how far it can jump from each stone: from stone i it can jump to any stone i + j where 0 <= j <= nums[i], as long as the stone exists.
Return the smallest number of jumps needed to reach the last stone. The tests always allow the frog to reach it.
Examples
Example 1:
Input: nums = [3,1,1,1,1]
Output: 2
Explanation: Jump 3 steps to the fourth stone, then 1 step to the last one. That is 2 jumps.
Example 2:
Input: nums = [1,1,1,1]
Output: 3
Explanation: Each stone allows only one step, so 3 jumps are needed.
Example 3:
Input: nums = [5]
Output: 0
Explanation: The frog is already on the last stone, so it needs 0 jumps.