Standard Bar Greedy Approach · Medium O(n) · O(1)
The same relay network now charges per hop, so the courier wants the minimum number of relays to reach the final post. Dispatch proceeds in waves: within the current wave's reachable band, scout the farthest post any member can open up; when the band is exhausted, that scout becomes the next wave's frontier and the hop counter rises by one.
Input: An integer array nums where nums[i] is the maximum hop length from index i.
Output: Return the minimum number of hops needed to reach the last index.
1 <= nums.length <= 10^40 <= nums[i] <= 10^5The last index is always reachableInput: {"nums":[2,3,1,1,4]}
Output: 2
One hop reaches index 1, whose 3-hop range lands on the last index.
Input: {"nums":[2,3,0,1,4]}
Output: 2
A different second hop (through index 1 to index 4) still needs only two waves.