HardGraphs · Eulerian Path · DFS

Reconstruct Flight Path

Each ticket [from, to] is one flight. Starting at "JFK", use every ticket exactly once and return the itinerary. If several work, return the lexicographically smallest.

[["BUF","HOU"],["HOU","SEA"],["JFK","BUF"]] → ["JFK","BUF","HOU","SEA"][["HOU","JFK"],["SEA","JFK"],["JFK","SEA"],["JFK","HOU"]] → ["JFK","HOU","JFK","SEA","JFK"]

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Variables

The data structures the code is building

Airports and tickets

Each arrow is one ticket; numbers show the order used

Time and space complexity

E = number of tickets, V = airports. The highlighted row is the solution being traced.

Keyboard: ← → step, Space play or pause. Up to 10 tickets and 7 airports, 3-letter codes, and the tickets must form a trip from JFK.