Problem
A car drives east toward a destination target miles away. It starts with start_fuel (startFuel in TypeScript) liters, burns one liter per mile, and has an unlimited tank. Along the way are gas stations stations[i] = [position_i, fuel_i]: stopping there adds fuel_i liters.
Return the minimum number of refueling stops needed to reach the target, or -1 if it cannot be reached. Arriving somewhere with exactly 0 fuel left still counts as arriving.
Example 1
- Input
- target = 100, start_fuel = 10, stations = [[10, 60], [20, 30], [30, 30], [60, 40]]
- Output
- 2
Example 2
- Input
- target = 100, start_fuel = 1, stations = [[10, 100]]
- Output
- -1
Example 3
- Input
- target = 1, start_fuel = 1, stations = []
- Output
- 0
In the first example, stop at mile 10 (60 liters, reach mile 70), then at mile 60 (40 liters, reach mile 110).
Constraints
1 <= target, start_fuel <= 10^90 <= stations.length <= 500Station positions strictly increase and are all below target.1 <= fuel_i <= 10^9