#182MediumGreedy· Interval Reach (Jump Game)
Fewest Hops to the Last Platform
Input format
`hops`: an array of non-negative integers, one per platform.
Output format
An integer: the minimum number of hops from platform 0 to platform n - 1.
Examples
Input: hops = [2, 3, 1, 1, 4]
Output: 2
Hop from platform 0 to platform 1 (distance 1), then from platform 1 to platform 4 (distance 3): 2 hops.
Input: hops = [2, 3, 0, 1, 4]
Output: 2
Platform 2 is a dead end, but it can be flown over: 0 -> 1 -> 4 still takes 2 hops.
Input: hops = [0]
Output: 0
The drone is already on the last platform, so no hops are needed.
Constraints
- 1 <= hops.length <= 10^5
- 0 <= hops[i] <= 1000
- The last platform is reachable from platform 0.
Study first
- #greedy
- #arrays
- #jump-game
- #breadth-first-search