Dsa
Sorting
Medium
Ticket Booking Sorting
You are managing a ticket booking system where each booking is represented by a customer name and the time of booking in the format 'Customer,HH:MM'. Your task is to sort the bookings by time in ascending order. If two bookings have the same time, sort them by the customer name alphabetically. Print the sorted bookings in the original format.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of bookings.
- The following n lines each contain a booking record.
Output format:
- Print the sorted booking records, one per line.
Example:
Input:
4
Alice,10:30
Bob,09:15
Charlie,10:30
Dave,09:00
Output:
Dave,09:00
Bob,09:15
Alice,10:30
Charlie,10:30
Key concepts
sortingtuplestime manipulation
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