Reconstruct Itinerary
Explore how to reconstruct a valid travel itinerary from a list of airline tickets by modeling the problem as a graph. Learn to build a graph representation, use a lexically sorted adjacency list, and apply a post-order depth-first search to determine the correct path. This lesson helps you understand graph traversal techniques and their application to real-world problems, enhancing your coding interview skills in Elixir.
We'll cover the following...
Description
Assume we have an array of airline tickets represented as pairs of departure and arrival airports like [from, to]. We have to reconstruct the itinerary in order. All tickets belong to a man who departs from a specified location, e.g., JFK. Therefore, the itinerary must begin with JFK. There might be multiple valid itineraries; you must return the itinerary with the smallest lexical order.
Constraints
Consider the following constraints:
- 1 <=
tickets.length<= 300 tickets[i].lengthmust be 2.- , == 3