Fewest Jumps to the End
You stand on index 0 of nums. From index i you may jump forward by any distance from 1 up to nums[i].
Return the fewest jumps needed to reach the last index. The last index can always be reached in the tests.
Example 1
nums [2,3,1,1,4]
returns 2
Jump to index 1, then to the end: 2 jumps.
Example 2
nums [1]
returns 0
Already at the end: 0 jumps.
Constraints
1 <= len(nums) <= 300 <= nums[i] <= 6- The last index is reachable.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Greedy problems
- Fewest PlatformsMedium
- Fewest Routers for a CorridorMedium
- Jump GameMedium
- Largest Tidy Number BelowMedium
- Make Letter Counts DistinctMedium
- Most Fairs VisitedMedium
- Shortest Schedule With CooldownMedium
- Smallest Joined NumberMedium