Back to problems

Reconstruct Itinerary II

Algorithm · Pinterest · Hard

Requirements You receive airline tickets as [departure, arrival] pairs. Build an itinerary that begins at JFK and consumes each ticket one time only. When more than one valid route is possible, choose the itinerary whose concatenated airport codes form the lexicographically earliest string. Follow-up: support ticket networks containing cycles, meaning that an itinerary may visit a city again. Examples Input: [["JFK", "MIA"], ["MIA", "ORD"], ["ORD", "JFK"], ["JFK", "SEA"]]…

Checking your access…