Reported July 2026
Goldman Sachsgraph

Cheapest Flights Within K Stops

Reported by candidates from Goldman Sachs's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Goldman Sachs OA. Under 2s to a working solution.
Founder's read

Goldman Sachs reportedly put Cheapest Flights Within K Stops in front of candidates in July 2026, and the trap is baked into the title. Plain Dijkstra looks right and quietly returns wrong answers. If your OA invite lists this one, the pattern is shortest path with a hop limit, and the fix is small once you see it. The second example is the tell: k = 0 forces the direct 500 flight over the cheaper two-hop route. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but you can know this one cold in an evening.

The problem

There are n cities labeled from 0 to n - 1. Each directed flight [from, to, price] travels from one city to another for the given price.
Return the minimum price of a route from src to dst that uses at most k intermediate stops. Return -1 if no such route exists.

Function
findCheapestPrice(n: int, flights: int[][], src: int, dst: int, k: int) → int

Examples
Example 1
n = 4
flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]]
src = 0
dst = 3
k = 1
return = 700
With at most one intermediate stop, the cheapest valid route is 0 -> 1 -> 3.
Example 2
n = 3
flights = [[0,1,100],[1,2,100],[0,2,500]]
src = 0
dst = 2
k = 0
return = 500

Reported by candidates. Source: FastPrep

Pattern and pitfall

The naive move is Dijkstra on price alone. It breaks because the cheapest path to a city may use too many stops, while a pricier path with fewer stops is the only one that can still reach dst. Pruning by cost throws that path away. The clean fix is Bellman-Ford limited to k+1 rounds. Keep a distance array, and each round relax every flight using a copy of the previous round's distances. Skipping the copy is the classic bug, because it lets a single round chain several edges and silently breaks the stop limit. Also remember k stops means k+1 edges. Return -1 if dst stays infinite. Complexity is O(k * E). A BFS by levels with pruning also works. If you freeze on the copy detail or the off-by-one during the live OA, StealthCoder is the hedge that gets you unstuck.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Cheapest Flights Within K Stops cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as cheapest flights within k stops. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Goldman Sachs's OA.

Goldman Sachs reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Cheapest Flights Within K Stops FAQ

What's the trick in Cheapest Flights Within K Stops?+

Limit the search by edges, not just cost. Run Bellman-Ford for k+1 rounds, relaxing flights against a copy of the previous round's distances. That copy guarantees each round adds at most one flight, so the stop limit holds and cheaper-but-longer paths can't sneak in.

Why does plain Dijkstra fail here?+

Dijkstra discards a city once it finds its cheapest cost, ignoring how many stops it took. The cheapest route to a city might use too many stops to ever reach dst within k. You'd need to track stops in the state, otherwise answers come out wrong.

Is k stops the same as k edges?+

No. k intermediate stops means at most k+1 flights. In Example 2, k = 0 allows exactly one flight, so the direct 500 flight wins over the 200 total two-hop route. Off-by-one here is the most common wrong answer on this problem.

How hard is this really for a Goldman Sachs OA?+

Medium. The graph is simple, but the stop constraint catches people who reach for Dijkstra on autopilot. If you know Bellman-Ford with a distance copy per round, it's about twenty lines. Most failures are the off-by-one or the missing copy.

How do I prepare in 48 hours?+

Code the Bellman-Ford version from scratch twice, then test it on both examples by hand. Trace Example 1 with k = 1 to confirm 700. Then write a variant using BFS by levels. Focus on the copy step and the k+1 loop bound.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Goldman Sachs.

OA at Goldman Sachs?
Invisible during screen share
Get it