FastPrepMinimum Refueling Stops
Problems/Minimum Refueling Stops

Minimum Refueling Stops

Uber logoUber● HardFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report identifies a variant of Minimum Number of Refueling Stops and an optimization follow-up, but omits the variant and edge conventions. The judged core task matches the visible source at about 92%.

A car starts at position 0 with startFuel units of fuel and must reach position target. It consumes one unit of fuel per unit of distance.

Each station is [position, fuel]. On reaching a station, the car may stop once and take all of that station's fuel, or skip it. Return the minimum number of stops needed to reach target, or -1 if the target is unreachable.

For this exercise, station positions are distinct and strictly between 0 and target. The input may be unsorted and may be normalized into increasing position order.

Function

minRefuelStops(target: int, startFuel: int, stations: int[][]) → int

Examples

Example 1

target = 100startFuel = 10stations = [[10,60],[20,30],[30,30],[60,40]]return = 2

Stop at positions 10 and 60. Their fuel is sufficient to reach the target in two stops.

Example 2

target = 100startFuel = 1stations = [[10,100]]return = -1

The car cannot reach the station at position 10, so no stop is possible.

Constraints

  • 1 <= target <= 10^9
  • 0 <= startFuel <= 10^9
  • 0 <= stations.length <= 2 * 10^5
  • Each station is [position, fuel], with distinct position strictly between 0 and target.
  • 1 <= fuel <= 10^9.

More Uber problems

  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int minRefuelStops(int target, int startFuel, int[][] stations) {
        // Write your code here.
    }
}
Checking account…