Skip to main content
Crowdfunding
Python + AI for Geeks
Practice

Coding Quiz - Finding Travel Routes

In this coding problem, you will write a function to find possible travel routes using the given flight tickets by utilizing a graph traversal algorithm.

You are provided with several flight tickets, and each ticket contains a departure city and a destination city.

Your goal is to list the sequence of cities visited using all the tickets.

If there are multiple possible routes, you should choose the route that is alphabetically first.


Write Code
def solution(tickets):
# Write your code here
return



Constraints

  • Each ticket must be used exactly once.

  • The route must start at 'ICN' airport.

  • The number of given tickets ranges from 1 to 10,000.

  • Each ticket's departure and arrival are represented by a 3-letter uppercase alphabet code.




Input/Output Example

  • Input: [["ICN", "JFK"], ["HND", "IAD"], ["JFK", "HND"]]
  • Output: ["ICN", "JFK", "HND", "IAD"]



Explanation

  • Using the given tickets, the possible route is "ICN" -> "JFK" -> "HND" -> "IAD".

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.