Unicorns OA Coding Interview Question: Reconstruct Itinerary from Boarding Passes

15 Views
No Comments

Given the following list of boarding passes, write some code which returns the itinerary of the trip.

Boarding passes:

SYD -> LAX
LHR -> DEL
SFO -> JFK
DEL -> PEK
JFK -> LHR
PEK -> SYD

Expected result:

SFO
JFK
LHR
DEL
PEK
SYD
LAX

This problem asks you to reconstruct a trip itinerary from a set of boarding passes. Each pass represents a directed edge from one city to the next, so the main task is to identify the starting city and then follow the chain until the route ends. A common solution is to use hash maps to track the next destination for each city and compute in-degrees and out-degrees to find the unique starting point. In the example, the itinerary is SFO -> JFK -> LHR -> DEL -> PEK -> SYD -> LAX.

END
 0