You are given a huge list of airline ticket prices between different cities around the world on a given day. These are all direct flights. Each element in the list has the format (source_city, destination, price).
Consider a user who is willing to take up to k connections from their origin city A to their destination B. Find the cheapest fare possible for this journey and print the itinerary for that journey.
For example, our traveler wants to go from JFK to LAX with up to 3 connections, and our input flights are as follows:
This problem was asked by Airbnb.
You are given a huge list of airline ticket prices between different cities around the world on a given day. These are all direct flights. Each element in the list has the format (
source_city
,destination
,price
).Consider a user who is willing to take up to
k
connections from their origin cityA
to their destinationB
. Find the cheapest fare possible for this journey and print the itinerary for that journey.For example, our traveler wants to go from
JFK
toLAX
with up to 3 connections, and our input flights are as follows:Due to some improbably low flight prices, the cheapest itinerary would be
JFK -> ATL -> ORD -> LAX
, costing $440.