Code RoomReconstruct itinerary
HardPrep Room Coding #1475

Reconstruct itinerary

CodingAlgorithms & data structuresSenior–Staff~35 min

You are given a list of airline tickets [from, to]. All tickets belong to a person who departs from 'JFK', and you must reconstruct the itinerary that uses every ticket exactly once. If multiple valid itineraries exist, return the one with the smallest lexical order when read as a single concatenated list of airport codes. A valid itinerary using all tickets is guaranteed to exist. Return the ordered list of airports visited.

Implement
find_itinerary(tickets: list[list[str]]) → list[str]
Examples
in[[["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]]out["JFK","MUC","LHR","SFO","SJC"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[[["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]]["JFK","MUC","LHR","SFO","SJC"]not run yetsample