Dsa
Sorting
Hard
Parking Lot Management
You are managing a parking lot with a list of cars and their associated parking time. Each car is identified by a license plate and the amount of time (in minutes) it has been parked. You need to sort this list by the time parked (in ascending order) and, if times are equal, by license plate in alphabetical order.
Input:
The first line contains an integer n (1 ≤ n ≤ 1000), the number of cars. The next n lines contain a string (the license plate) followed by an integer (the parking time in minutes), separated by a space.
Output:
Print the sorted list of parked cars in the format 'License Plate: Minutes'.
Example:
Input:
3
ABC123 10
XYZ567 5
DEF456 10
Output:
XYZ567: 5
ABC123: 10
DEF456: 10
Key concepts
sortingarrayscustom_sort
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