Minimum Number of Refueling Stops
A hard-tier problem at 41% community acceptance, tagged with Array, Dynamic Programming, Greedy. Reported in interviews at Barclays and 5 others.
Minimum Number of Refueling Stops is a hard problem that appears in interviews at Barclays, DE Shaw, Morgan Stanley, Snap, Flipkart, and Rubrik. You're given a car, a target distance, and a list of gas stations with fuel amounts. The trap is thinking greedy first: take the cheapest or nearest station. That fails. You need to know when to backtrack and swap your choice for a better one. Only about 41% of candidates pass it on first submission. If you hit this problem live and your greedy instinct breaks, StealthCoder surfaces the optimal solution invisible to the proctor.
Companies that ask "Minimum Number of Refueling Stops"
Minimum Number of Refueling Stops is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is reversing your perspective. Instead of deciding which stations to stop at as you drive forward, use a max heap to track the best refueling options you've passed, then decide retroactively which one to use when you run out of gas. This is a greedy choice with dynamic programming flavor: you commit to the minimum number of stops, and at each shortfall, you 'rewind' to grab the station with the most fuel. The naive approach tries to build a set of stops upfront and fails on tie-breaking. The heap approach guarantees you never backtrack more than necessary. When you're coding live and the standard DP recurrence feels clunky, the heap-based greedy method is your escape hatch. StealthCoder solves this pattern in seconds, which matters if the problem hits your assessment and you're under time pressure.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum Number of Refueling Stops recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Number of Refueling Stops interview FAQ
Why doesn't a simple greedy approach work here?+
A greedy approach that picks stations on the fly doesn't account for stations you've passed. You might skip a high-fuel station early, then regret it later. The heap method lets you retroactively 'choose' the best station you've already seen, effectively solving a global optimization problem instead of a local one.
Is this still asked at top finance and tech firms?+
Yes. The problem appears in interviews at Barclays, Morgan Stanley, and DE Shaw, among others. It's a signature question for roles testing algorithmic depth. The 41% acceptance rate reflects its difficulty and the fact that many candidates default to broken greedy logic.
What's the relationship between the heap and dynamic programming here?+
The heap is the mechanism that makes the greedy choice valid. You're not using full DP with a table. Instead, the heap implicitly tracks all viable states (past stations you could have stopped at), and you greedily pick the maximum-fuel option at each critical point. It's DP-adjacent reasoning with a greedy execution.
What's the most common mistake candidates make?+
Trying to pre-compute which stations to stop at before driving. This locks you into bad choices early. The correct approach processes the problem in driving order, but uses the heap to revise past decisions. Candidates who don't see the 'retroactive choice' angle run into intractable state space or wrong answers.
How does this fit with Array, Greedy, and Heap topics?+
You iterate the array of stations in order (Array), decide at each step whether to 'use' a past station based on a max heap (Heap), and the heap-based selection is the greedy strategy (Greedy). Dynamic Programming is implicit in the state tracking. All four topics converge in one solution.
Want the actual problem statement? View "Minimum Number of Refueling Stops" on LeetCode →