Jump Game II
MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.Same board as Jump Game: from index i you may jump forward up to nums[i] places. This time the last index is always reachable. Return the fewest jumps needed to get there from index 0.
nums = [2, 3, 1, 1, 4] → 2 (0 → 1 → 4)
nums = [2, 3, 0, 1, 4] → 2
nums = [0] → 0 (already there)Constraints
1 <= nums.length <= 10^40 <= nums[i] <= 1000- The last index can always be reached.