Minimum Number of Refueling Stops
A car travels from a starting position to a destination which is target miles east. Along the way, there are gas stations. Return the minimum number of refueling stops the car must make to reach destination. If it cannot reach the destination, return -1.

30:00

Minimum Number of Refueling Stops
hard
Topics
Companies

A car travels from a starting position to a destination which is target miles east. Along the way, there are gas stations. Return the minimum number of refueling stops the car must make to reach destination. If it cannot reach the destination, return -1.

Example 1:
Input: {"target":100,"startFuel":10,"stations":[[10,60],[20,30],[30,30],[60,40]]}
Output: 2
Constraints:
  • 1target,startFuel1091 \leq \text{target}, \text{startFuel} \leq 10^9

  • 0stations.length5000 \leq \text{stations.length} \leq 500

  • 1positioni<positioni+1<target1 \leq \text{position}_i < \text{position}_{i+1} < \text{target}

  • 1fueli1091 \leq \text{fuel}_i \leq 10^9

Input
arr ={"target":100,"startFuel":10,"stations":[[10,60],[20,30],[30,30],[60,40]]}

100 miles to go on 10 gallons, past 4 stations.

State
target
100
startFuel
10
reach
10
stops
0
stations
[[object Object], [object Object], [object Object], [object Object]]
heap
[]
Variables
target=100
startFuel=10
stations=4
Variables
VariableValue
target100
startFuel10
stations4
DepthFunction Call
Stack empty
0/9