Dsa
Sorting
Medium
Travel Itinerary Sorter
You are given a list of travel itineraries, each represented as a tuple containing a city name, a start date, and an end date. Your task is to sort these itineraries first by the start date and then by the end date for itineraries that start on the same date.
Input format:
- The first line contains an integer N (1 <= N <= 1000), the number of itineraries.
- The next N lines contain a string in the format "City, StartDate, EndDate" where StartDate and EndDate are in the format YYYY-MM-DD.
Output format:
- Print the sorted itineraries, one per line.
Example:
Input:
3
London, 2023-05-12, 2023-05-15
Paris, 2023-05-10, 2023-05-12
London, 2023-05-10, 2023-05-13
Output:
London, 2023-05-10, 2023-05-13
Paris, 2023-05-10, 2023-05-12
London, 2023-05-12, 2023-05-15
Key concepts
sortingtuplescustom
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now