Minimum Number of Refueling Stops
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A car drives east from position 0 toward a destination target miles away. It starts with startFuel liters in an unlimited tank and burns exactly one liter per mile.
Along the way are gas stations: stations[i] = [position_i, fuel_i] means a station position_i miles from the start that holds fuel_i liters. If the car reaches a station it may stop and take all of that station's fuel. Reaching a station or the target with exactly 0 fuel left still counts as reaching it.
Return the minimum number of refueling stops needed to reach target, or -1 if it is impossible. Aim for O(n log n).
Examples
Constraints
- 1 <= target, startFuel <= 10^9
- 0 <= stations.length <= 500
- 1 <= position_1 < position_2 < ... < position_n < target
- 1 <= fuel_i <= 10^9
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.