Practice: Reconstruct Itinerary

Problem: https://leetcode.com/problems/reconstruct-itinerary/

Status: rare but worth recognizing. This is the one problem in the week to recognize rather than over-drill. Eulerian paths appear far less often in standard screens than Dijkstra, Bellman-Ford, or Union-Find, so the goal here is that the use-every-edge cue fires and you know Hierholzer’s is the tool, not that you can reproduce it cold under pressure. Spend your from-memory reps on the practiced core; give this one a single honest pass and move on.

Recognition reminder: each ticket is a directed edge from one airport to another, and you must use every ticket exactly once, starting at “JFK”. “Traverse every edge exactly once” is the signature of an Eulerian path, which is a different question from a shortest path entirely: you are not minimizing a cost, you are consuming all the edges in a single continuous walk. The added wrinkle is the tie-break: when more than one valid itinerary exists, you must return the one that is smallest in lexical order, so the order in which you consider an airport’s outgoing tickets matters. Think about how you would walk edges and delete each as you use it, and what to do when you walk into a dead end before all tickets are spent.

Before you start (the five-beat rhythm)

  1. Your Pattern Card for this week is already written.
  2. Name the pattern aloud and write your approach as a plain-English comment before any code.
  3. Struggle floor: 25 minutes unaided. No hints, no AI, no Discuss tab.
  4. If stuck past the floor, ask the tutor for a hint. Six rungs, one per ask.
  5. Debrief in your commit message before moving to the next problem.

Your target

Fill these in yourself before you look at anyone else’s solution:

Target time complexity:  ____
Target space complexity: ____

Express your target in terms of the number of tickets (edges) E. The lexical-order requirement suggests sorting somewhere; account for its cost, and decide where in the process the sort belongs.

Where your code goes

Write your solution in your own work repo (see getting-started.md), not in this folder. This folder ships only the problem spec and a provided-example test (tests/test_provided.py) so you can check the given cases locally before you submit to LeetCode’s judge. The judge is the oracle; the tutor will not confirm your answer by reading it.

Debrief (paste into your commit message)

1. What pattern did this turn out to be?
2. What was the trigger phrase or input shape that should have made me reach for it?
3. What was the time and space complexity, and what would dominate at scale?
4. What edge case would have broken my first attempt?
5. What would I do differently in three days when I see this cold?