Lecture
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".
Previous lessonExplanation of Integer List with Sum Greater Than TargetNext lessonFinding Travel Itinerary Explanation
Lessons in this chapter · Practice with Common Coding Quiz Types
- 1. Coding Quiz - Finding Rotten Apples
- 2. Finding Rotten Apples Explained
- 3. Coding Quiz - Calculating the Sum of a List Recursively
- 4. Explanation for Recursively Calculating the Sum of a List
- 5. Coding Quiz - 1, 2, 3 Addition
- 6. Explanation for Adding 1, 2, 3
- 7. Coding Quiz - Flattening a 2D Array
- 8. Converting to a 1D Array Explanation
- 9. Coding Quiz - Calculate the Sum of a List Using Divide and Conquer
- 10. Explanation of Calculating the Sum of a List Using Divide and Conquer
- 11. Coding Quiz - Gym Uniform Problem
- 12. Gym Uniform Problem Explanation
- 13. Coding Quiz - List of Integers with Sum Greater than Target
- 14. Explanation of Integer List with Sum Greater Than Target
- 15. Coding Quiz - Finding Travel Routes
- 16. Finding Travel Itinerary Explanation
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help