Minimum Number of Refueling Stops
master · 1665 · lc hard +32 · verified · 41.1% accepted · 4,864 likes · top 21%
Description
A car sets out from a starting position toward a destination target miles to the east. Along the route, gas stations are represented by stations where stations[i] = [positioni, fueli] gives the mile marker and available fuel (in liters) at each station.
The car begins with startFuel liters of fuel and consumes one liter per mile. At any station, the car may stop and take all available fuel. The tank has unlimited capacity.
Return the minimum number of refueling stops required to reach the destination. If it is impossible, return -1.
A car that arrives at a station or the destination with exactly 0 fuel is still considered to have reached it.
Example 1:
Example 2:
Example 3:
Code