Booking.com Coding Interview: Flight Ticket Trip Rebuilder
Based on questions reported for Booking.com interviews
The interviewer opens
Hi, and thanks for joining; welcome to your interview for the software engineer role at Booking.com. We'll work through one coding problem together, and I'd like you to think out loud as you code. If you need to step out or take a break, you can pause any time with the Pause button at the top right.
The problem is about rebuilding a traveler's trip from a pile of shuffled flight tickets, which is the kind of itinerary puzzle that comes up in travel. It's in the Problem tab on the right, so please read it through and ask me anything before you start.
The problem
A traveler hands you their flight tickets in random order; rebuild the trip starting from their home airport.
tickets: list of tickets, each{src, dst}with 3-letter uppercase airport codes.home: the airport the trip starts from.
Each airport is the departure airport of at most one ticket. Return the list of airports visited in order, starting with home, using every ticket exactly once (length = number of tickets + 1). The input always admits exactly such a trip.
Example: tickets = [{JFK→SFO}, {AMS→LHR}, {LHR→JFK}], home = "AMS" → ["AMS", "LHR", "JFK", "SFO"]
Up to 10^4 tickets.