Problem
You get a list of airline tickets tickets. Each item [from, to] is one flight from the airport from to the airport to. Each airport has a code of three letters.
Build an itinerary that starts at "JFK" and uses every ticket exactly one time. An itinerary is the list of airports in the order of your visits.
At least one correct itinerary exists. If more than one itinerary is correct, return the itinerary that is first in lexical order.
Lexical order compares two lists item by item, and the first different item decides the order. Two airport codes compare in the same way as two words in a dictionary.
Example 1
- Input:
- tickets = [["JFK","LAX"],["LAX","SEA"],["SEA","JFK"],["JFK","BOS"]]
- Output:
- ["JFK","LAX","SEA","JFK","BOS"]
- Explanation:
- An itinerary that flies to
"BOS"first comes earlier in lexical order. But no ticket leaves"BOS", so that itinerary cannot use all the tickets.
Example 2
- Input:
- tickets = [["JFK","ORD"],["JFK","DEN"],["DEN","JFK"],["ORD","JFK"]]
- Output:
- ["JFK","DEN","JFK","ORD","JFK"]
- Explanation:
- You can do the two round trips in either order. The itinerary that visits
"DEN"first is first in lexical order.
Constraints
- 1 <= tickets.length <= 300
- tickets[i].length == 2
- from.length == 3
- to.length == 3
- from and to have only uppercase English letters
- from != to
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Accounts Merge
Coding · Array · Breadth-First Search · Depth-First Search
- Alien Dictionary
Coding · Array · Breadth-First Search · Depth-First Search
- Design Search Autocomplete System
Coding · Data Stream · Depth-First Search · Design
- Evaluate Division
Coding · Array · Bellman–Ford Algorithm · Breadth-First Search
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 4 records
Amazon
Leetcode 332. Reconstruct Itinerary
Reported Sep 30, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceAnduril
Leetcode 332. Reconstruct Itinerary
Reported Nov 1, 2026 · 2 source reports
SENIOR
Source snapshot: Nov 12, 2026
View sourceGoogle
Leetcode 332. Reconstruct Itinerary
Reported Jan 23, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourcePinterest
Leetcode 332. Reconstruct Itinerary
Reported Sep 10, 2026 · 11 source reports
MID_LEVEL, SENIOR, STAFF
Source snapshot: Nov 12, 2026