Graph Theory37 sections · 1633 units
Open in Course

Problem - Reconstruct Itinerary

LeetCode 332 - Lexicographically smallest path.

Problem: You have a list of airline tickets as pairs [from, to]. Reconstruct the itinerary starting from "JFK". If multiple valid itineraries exist, return the lexicographically smallest one.

Link: LeetCode 332

Example:

  • Input: [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
  • Output: ["JFK","ATL","JFK","SFO","ATL","SFO"]

Note: You must use all tickets exactly once. This is an Euler path with a twist.