Minimum Number of Refueling Stops

Hard · Heap & Priority Queue · about 30 minutes

Asked at Uber, Google, Amazon, Meta.

A car starts with startFuel liters and must travel target miles east, using one liter per mile. stations[i] = [position, fuel] describes gas stations in increasing order of position; stopping at one adds all its fuel. Return the minimum number of stops needed to reach the target, or -1 if impossible. Arriving with 0 fuel (at a station or the target) is fine.

Related guides