Dsa
Sorting
Easy
Sort Car Models by Year
You are given a list of car models along with their release years. Each model is represented as a string 'Model Year'. Your task is to sort these models by their release year, and by model name alphabetically for those released in the same year.
Input:
- The first line contains an integer N (1 ≤ N ≤ 100) indicating the number of car models.
- The next N lines each contain one car model in the format 'Model Year'.
Output:
- A single line with the sorted car models, separated by commas.
Example:
Input:
3
Civic 2020
Accord 2018
Model S 2019
Output:
Accord 2018, Model S 2019, Civic 2020
Key concepts
sortingdictionariesstrings
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