MEDIUMasked at 9 companies

Cheapest Flights Within K Stops

A medium-tier problem at 40% community acceptance, tagged with Dynamic Programming, Depth-First Search, Breadth-First Search. Reported in interviews at MakeMyTrip and 8 others.

Founder's read

Cheapest Flights Within K Stops is a medium-difficulty graph problem asking you to find the minimum cost path from one city to another with a constraint on the number of intermediate stops allowed. It's been asked by Airbnb, Apple, Stripe, Snap, and others. The acceptance rate sits around 40%, which means most candidates either nail it or struggle hard. The trap is thinking this is a plain shortest-path problem. It's not. The K-stops constraint breaks Dijkstra's algorithm and forces you to track state differently. If this problem hits your live assessment and you blank on the trick, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
9
Difficulty
MEDIUM
Acceptance
40%

Companies that ask "Cheapest Flights Within K Stops"

If this hits your live OA

Cheapest Flights Within K 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. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.

Get StealthCoder
What this means

The standard shortest-path intuition fails because you can't just pick the globally cheapest edge at each step. You have to track both the cost and the number of stops taken, making this a constrained optimization problem. Most candidates attempt Dijkstra without the stops dimension, or they try greedy and get burned. The right approach is to either use Bellman-Ford modified for the K-constraint, or BFS-with-priority-queue where state is (cost, node, stops-used). Many also miss that a longer path by cost can be valid if it uses fewer stops. You'll need to revisit nodes multiple times with different stop counts. The dynamic programming angle is tracking the minimum cost to reach each node at each stop level (0 stops, 1 stop, 2 stops, etc.). Common pitfall: initializing distance arrays wrong or pruning states too early. StealthCoder is the hedge here if you've drilled shortest-path problems but haven't internalized the stops constraint twist.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Cheapest Flights Within K Stops recycles across companies for a reason. It's medium-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. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Cheapest Flights Within K Stops interview FAQ

Is this really just Dijkstra with a twist?+

No. Dijkstra picks the globally smallest edge and never revisits a node. Here, you must revisit nodes if you have stops left, because a costlier path with fewer stops used might lead to a cheaper overall answer later. You're optimizing two dimensions at once: cost and stops consumed.

Why do so many people fail this at Airbnb or Apple?+

They see 'shortest path' and code Dijkstra from muscle memory. Then they hit test cases where the constraint buckles their solution. The problem requires thinking of state as (destination, stops-remaining) not just (destination). That mental pivot catches unprepared candidates.

What's the real trick to solving this efficiently?+

Use a priority queue ordered by cost, and track (cost, node, stops-used) as your state tuple. Process nodes multiple times if you've used fewer stops than before. Or use DP: dist[stop_level][node] = min cost to reach node using exactly that many stops. Both work; queue-based is closer to intuition.

Do I need to know all six topics listed to solve this?+

Not all equally. Priority Queue and Shortest Path are core. BFS and DP are valid solution approaches. DFS works but less efficient. Graph basics are assumed. You pick one algorithmic family, not all six. Most candidates use either BFS-with-heap or DP.

How hard is 40% acceptance really?+

It means 6 in 10 people get it wrong in the live session. Most fail because they apply the wrong mental model (pure shortest-path) or miss the stop-counting dimension entirely. It's not a 'hard' problem algorithmically, but the constraint logic catches overconfident candidates off guard.

Want the actual problem statement? View "Cheapest Flights Within K Stops" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.