Dsa
Sorting
Warm-up
Sort Tech Items by Model Year
You are tasked with managing a list of tech items and their model years. Write a program that sorts these items in descending order based on their model years. If two items have the same model year, sort them alphabetically by the item name.
Input:
The first line contains an integer I, the number of tech items. The next I lines each contain the item name (a string) followed by its model year (an integer).
Output:
Print the sorted list of items with their model years in the format 'ItemName Year'.
Example:
Input:
4
Laptop 2020
Phone 2021
Tablet 2019
Smartwatch 2019
Output:
Phone 2021
Laptop 2020
Tablet 2019
Smartwatch 2019
Key concepts
sortingdata structurebasic
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