AO
Back

Reconstruct an Itinerary From Tickets, Start Not Given (LC 332)

Also reported as LeetCode 332

CodingOnsiteLast reported September 2026Medium Frequency

Problem Overview

The round: eight Pinterest reports, posted from December 2025 to September 2026, name this problem: four phone or technical screens and four onsite coding rounds, one of them in an MLE loop. Most name LeetCode 332, Reconstruct Itinerary, by number or title. The reported twists are about the start city: one onsite report says you must find the start yourself, and one phone screen says there is no fixed start and you take the start as an input. One onsite report says the first part had no loops, and the follow-up was how to handle a loop. Two graded parts.

Problem

You are given airline tickets, each a pair [from, to] of city names, in no particular order. Rebuild the trip that uses every ticket exactly once, as the list of cities in the order visited.

Part 1 — a simple route, no loops

def route_from_tickets(tickets: list[list[str]]) -> list[str]: ...
  • The tickets form one route that never visits a city twice, so there is exactly one answer. There is at least one ticket.
  • No start city is given. Find it yourself: it is the only city that is never a destination.
  • Example: [["B", "C"], ["A", "B"]] -> ["A", "B", "C"].

Part 2 — the route can loop back

def reconstruct_itinerary(tickets: list[list[str]], start: str | None = None) -> list[str]: ...
  • Now a city can be visited more than once, and the same [from, to] pair can appear on more than one ticket. Use every ticket exactly once. A valid trip always exists.
  • If start is given, the trip begins there. If not, find a valid start yourself.
  • When several trips are valid, return any one of them (the tests check that your trip is valid, not that it is one particular trip).
  • Example: [["JFK", "KUL"], ["JFK", "NRT"], ["NRT", "JFK"]] with start="JFK" -> ["JFK", "NRT", "JFK", "KUL"]. Going to KUL first leaves you stuck with two tickets unused.

Follow-up reported (not graded): printing the path. The poster first describes it as printing the full route reached from the given start, for example JFK SFO DFW, then says they misremembered and that the follow-up should be printing all paths. Ask whether that means the one full route or every route from the start.

Notes: the problem, the find-the-start twist, the start passed as an input, the no-loop first part and the loop follow-up are reported. Ours: the function names, the examples, and accepting any valid trip. LeetCode 332 itself always starts at JFK and asks for the trip that is smallest in lexical order; no report says which tie-break your round uses, so ask. The reference returns the lexically smallest trip, so it also answers the LeetCode version.

Speed is not graded here: the editor cannot time your code. Say what your version costs.

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Trade-off discussion · 2
Trade-off discussion

How do you handle a loop, where the trip comes back through a city?

Probes for: onsite, after a first part with no loops

Print the path: the poster describes the full route reached from the given start (for example JFK SFO DFW), then says it should be printing all paths. Ask which one is meant.

Probes for: phone screen with the start as an input

What Reports Emphasize

What the reports say: LeetCode 332 with the start city as the twist: one report says you find the start yourself, one phone screen takes it as an input. One onsite report gives a first part with no loops and then asks how to handle a loop; that candidate did not solve it. One reply calls the question very frequent.

Common mistakes (ours): Taking the first ticket's departure as the start; A greedy walk that never backs up; A set of destinations that drops duplicate tickets; Deep recursion on a long trip

Edge cases to test (ours): A single ticket; A round trip with no start; The same pair on two tickets; A dead-end ticket that must be used last

Alternative approaches (ours): Backtracking DFS over sorted destinations (simpler to explain, exponential in the worst case); Recursive Hierholzer if the trip is short

Practice

Write your own against 12 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Pinterest with friends?

Send them this page. It is free to read, no account needed.

More Pinterest Questions

Free preview

Every question in the Pinterest catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 70 Pinterest questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Pinterest · Coding · Reported 8× across candidate reports
Is this helpful?