Implement cheapest itinerary with date filters
CircleSoftware Engineer · Online AssessmentLast updated
This question evaluates proficiency in graph algorithms and constrained pathfinding, including handling date filters for initial departures, time-ordered connections, cycle avoidance, and quantitative complexity analysis.
Implement a function that computes the cheapest itinerary from a given origin to a destination using a list of flights, where each flight has (id, source, destination, departure_time, arrival_time, price). Only consider itineraries whose first departure falls within a provided date range. Return the minimum total price and the ordered list of flight IDs forming the itinerary; return -1 if no valid itinerary exists. Explain your algorithm, time/space complexity, and how you enforce time ordering between connections and avoid cycles.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.