Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Reconstruct Itinerary

Given airline tickets as (from, to) pairs, reconstruct the itinerary that starts at JFK and uses every ticket exactly once. If several itineraries exist, print the one that is smallest in lexicographic order.

Constraints

1 <= n <= 300 Airports are 3 uppercase letters

Discussion

No discussions yet.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.