Reconstruct Itinerary

Advanced

Reconstruct Itinerary

Hey kiddo! Imagine you have a magical travel itinerary that lists out the different places you're going to visit in order, but oh no! It got all scrambled up and you need to put it back in the right order!

Your task is to write a function that will help you unscramble the itinerary. You will get a list of flight paths, each represented by a pair of departure and arrival cities.

Your goal is to find the path that uses all the given connections exactly once, starting from the 'JFK' airport. You need to follow the flight connections in lexicographical order if there are multiple choices.

Here's an example to illustrate:

reconstruct_itinerary([["JFK", "SFO"], ["JFK", "ATL"], ["SFO", "ATL"], ["ATL", "JFK"], ["ATL", "SFO"]])

For the above example, your function should return:

["JFK", "ATL", "JFK", "SFO", "ATL", "SFO"]

This will be a fun way to practice your coding skills and learn about sorting and sequencing!

So, let's get started!

Geek
Inputs

Arg 1:

[["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
Expected Output
["JFK", "ATL", "JFK", "SFO", "ATL", "SFO"]
Actual Output