Cheapest Flights Within K Stops
Updated
Problem 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 Onsite Interview questions
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
- First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
- Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
- Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
- Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Shortest Hop Path Between MachinesGoogle · ONSITE INTERVIEWGoogle interview questions
- Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
- Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- All-Pairs Shortest PathsMorgan Stanley · OA · ONSITE INTERVIEWMorgan Stanley interview questions
- Minimum Path Cost with Edge DiscountsSkyscanner · ONSITE INTERVIEWSkyscanner interview questions
- Cheapest Flight with Its PathAirbnb · OA · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Maximum Gain on a Budgeted Returning WalkNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Cities on Shortest Delivery RoutesMathWorks · OAMathWorks interview questions
- Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
- Planets Queries from Planet OneAdyen · PHONE SCREENAdyen interview questions