FastPrepCheapest Flight with Its Path
Problems/Cheapest Flight with Its Path

Cheapest Flight with Its Path

Airbnb logoAirbnb● HardFULLTIMEINTERNOAPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports ask for the cheapest route within a stop limit and say the path must be returned. They leave out what to do when the target is unreachable and how to break ties between equal costs.

Our version is about 94% the same as the reported question.

There are n cities, numbered from 0 to n - 1. Each flight [from, to, price] goes one way only, from city from to city to. Every flight has a positive price.

Find the cheapest route from city src to city dst. A stop is a city where the route lands between src and dst. The route may make at most k stops, so it uses at most k + 1 flights.

Return an integer array. Its first element is the total price. The rest of the array lists the cities on the route in order, starting with src and ending with dst. If no route works, return [-1].

Several routes may share the lowest price. Then pick the one with fewer flights. If there is still a tie, compare the city lists from the left. At the first place where they differ, pick the route whose city number is smaller.

Function

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

Examples

Example 1

n = 4flights = [[0,1,100],[1,2,100],[2,3,100],[0,2,500],[1,3,600]]src = 0dst = 3k = 2return = [300,0,1,2,3]

With at most two stops, the route may use up to three flights. The route 0 → 1 → 2 → 3 uses three flights, makes two stops, and costs 300. Every other route to the destination costs more. So the answer is that price, followed by the four cities of the route in order.

Example 2

n = 3flights = [[0,1,100],[1,2,100],[0,2,500]]src = 0dst = 2k = 0return = [500,0,2]

No stop is allowed, so only a direct flight from the start city to the destination counts. The route through the middle city is cheaper, but it needs one stop. So the answer is the direct flight's price, followed by its start and end cities.

Constraints

  • 1 <= n <= 100.
  • 0 <= flights.length <= 5000.
  • flights[i].length == 3.
  • 0 <= from, to, src, dst < n.
  • from != to, and no two flights have both the same from and the same to.
  • 1 <= price <= 10^6.
  • 0 <= k < n.
  • Every valid route price fits in a signed 32-bit integer.

More Airbnb Online Assessment questions

  • Count Card Duel RoundsOA · Seen Nov 2026
  • Count Lamps Lighting Each PointOA · Seen Nov 2026
  • Simulate Orchard Rot SpreadOA · Seen Nov 2026
  • Sort Adjacent PairsOA · Seen Nov 2026
  • In-Memory File SystemOA · Seen Nov 2026
  • Task Management SystemOA · Seen Nov 2026
  • Recipe Management SystemOA · Seen Nov 2026
  • Progressive Banking SystemOA · Seen Nov 2026
  • Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
  • Parcel Attribute Store with TTLOA · Seen Oct 2026

Similar questions at other companies

  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
  • Minimum Path Cost with Edge DiscountsSkyscanner · ONSITE INTERVIEWSkyscanner 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
  • Cheapest Flights Within K StopsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • All-Pairs Shortest PathsMorgan Stanley · OA · ONSITE INTERVIEWMorgan Stanley interview questions
  • Cheapest Flights Within K StopsInMobi · OAInMobi interview questions
  • Minimum Leaf Path Sum over All RootsInfosys · OAInfosys interview questions
  • Largest Consistent Visiting GroupAuxoAI · OA

Interview reports that mention this question

  • Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
  • Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)

Airbnb interview experiences

  • Airbnb OA · November 2026
  • Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
  • Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
  • Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public int[] cheapestFlightPath(int n, int[][] flights, int src, int dst, int k) {
      // Write your code here.
    }
}
Checking account…