332. Reconstruct Itinerary
Practice Reconstruct Itinerary for free on NudgeCode: Hard, Graph pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Each tickets[i] = [from, to] is a one-way flight between two airports. A traveler starts at "JFK" and must use every ticket exactly once. Return the list of airports visited, in order.
There is always at least one way to use all the tickets. If there are several, return the one that is smallest in lexical order when compared airport by airport (so ["JFK","LGA"] comes before ["JFK","LGB"]). That answer is unique.
Example
tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]
-> ["JFK","MUC","LHR","SFO","SJC"]
Constraints
- 1 <= tickets.length <= 300
- Airport codes are 3 uppercase English letters
from != to; the same ticket can appear more than once