Reconstructing an Itinerary (Eulerian Path)

hard
Unit 23 · Trees & Graphs0/0 to milestone

Given airline tickets (from, to), reconstruct the itinerary that uses every ticket exactly once, starting from "JFK". If several itineraries work, return the lexicographically smallest one (as a list of airports). A valid itinerary always exists.

Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Reconstructing an Itinerary (Eulerian Path) · TechGradify