14. Reconstruct Itinerary
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
Map all the airports to their destination.Sort the destinations according to lexical order and then apply DFS.
Initialize a unordered map to store the destinations of every airport.
Sort the destinations according to their lexical order.
Call the DFS with the starting airport as "JFK".
In DFS run a while loop till the destinations are not over.
n loop get the first destination.
Remove it from the adjacency list.
Call the DFS(Recursion).
After the end of loop push the string into the ans.
Time Complexity: O(nlogn)
Auxiliary Space Complexity: O(nlogn)
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.