Your question is Reconstruct Itinerary Path. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
MakeMyTrip receives a list of directed itinerary segments, where each segment represents travel from one city to another. Given a starting city, reconstruct a valid route that uses every segment exactly once. If multiple valid routes exist, return the lexicographically smallest route by city code.
Implement reconstruct_itinerary(itineraries, start). itineraries is a list of pairs [from_city, to_city], and start is the starting city code. Return a list of city codes containing the starting city and one destination for every itinerary segment. The input is guaranteed to contain at least one valid route beginning at start. City codes are uppercase strings.
def reconstruct_itinerary(itineraries, start):