Reconstruct Itinerary
Use every directed flight ticket exactly once to form an itinerary starting at JFK. Among valid itineraries choose the lexicographically smallest airport sequence.
Example 1
tickets = [["JFK","BBB"],["JFK","AAA"],["AAA","JFK"]]["JFK","AAA","JFK","BBB"]Explanation
AAA first permits returning to JFK and taking BBB last; BBB first strands unused tickets.
Example 2
tickets = [["JFK","AAA"],["AAA","JFK"],["JFK","AAA"]]["JFK","AAA","JFK","AAA"]Explanation
Duplicate JFK->AAA tickets are separate edges and each is used.
Example 3
tickets = [["JFK","LAX"]]["JFK","LAX"]Explanation
The sole ticket gives the only itinerary.
Constraints
- 1 <= number of tickets <= 300
- Airport codes are three uppercase letters
- A valid itinerary exists
- Duplicate tickets are distinct usable edges
Function contract
findItineraryArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[["JFK","BBB"],["JFK","AAA"],["AAA","JFK"]]