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]]}

Target: 100 miles, Start fuel: 10, Stations: 4

State
target
100
startFuel
10
stationCount
4
Variables
No variables to display
DepthFunction Call
Stack empty
0/3