Problem · Array
Cheapest Flights Within K Stops
Learn this problemProblem statement
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) → intExamples
Example 1
n = 4flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]]src = 0dst = 3k = 1return = 700With at most one intermediate stop, the cheapest valid route is 0 -> 1 -> 3.
Example 2
n = 3flights = [[0,1,100],[1,2,100],[0,2,500]]src = 0dst = 2k = 0return = 500More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW · Seen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Word LadderPHONE SCREEN · Seen Jun 2026
- Log Buffer AnalyzerOA · Seen May 2026