Solution: Reconstruct Itinerary
Explore how to reconstruct a flight itinerary from a list of airline tickets starting at JFK using Hierholzer's algorithm. Understand the use of graph representation, depth-first search, and lexical sorting to find an Eulerian path that visits all edges exactly once. This lesson helps you implement and analyze the algorithm's time and space complexity to efficiently solve itinerary reconstruction problems.
We'll cover the following...
Statement
Given a list of airline tickets where tickets[i] = [fromi, toi] represent a departure airport and an arrival airport of a single flight, reconstruct the itinerary in the correct order and return it.
The person who owns these tickets always starts their journey from "JFK". Therefore, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should prioritize the one with the smallest
For example, the itinerary
["JFK", "EDU"]has a smaller lexical order than["JFK", "EDX"].
Note: You may assume all tickets form at least one valid itinerary. You must use all the tickets exactly once.
Constraints:
tickets.lengthtickets[i].lengthfromi...