As reported: Pinterest MLE tech screen (2025), coding question.
This is LeetCode 332 — Reconstruct Itinerary.
tickets[i] = [from, to] is a flight. Reconstruct the itinerary in order: it starts at "JFK" and uses every ticket exactly once. If several valid itineraries exist, return the one that is smallest in lexical order when read as a single string (["JFK","LGA"] comes before ["JFK","LGB"]).
All tickets together form at least one valid itinerary.
Example 1
tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]
Output: ["JFK","MUC","LHR","SFO","SJC"]
Example 2
tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
Output: ["JFK","ATL","JFK","SFO","ATL","SFO"]
["JFK","SFO","ATL","JFK","ATL","SFO"] is also valid but larger.
Constraints: 1 ≤ tickets.length ≤ 300; airport codes are 3 uppercase letters.
Code runner format: one JSON value per line: tickets. Implement findItinerary(tickets); the harness prints the itinerary.