Dsa
Sorting
Warm-up
Bakery Freshness Sorter
A bakery tracks its items by their 'Days Until Expiry' (integer) and 'Price' (float). To minimize waste, the baker wants to sort items such that those expiring soonest are sold first. If two items expire on the same day, the more expensive item should be listed first to maximize potential revenue. If both expiry and price are identical, sort alphabetically by the item name.
Input: The first line contains N. The next N lines contain: ExpiryDays Price Name.
Output: The sorted list of Names.
Example Input:
3
2 5.50 Cupcake
1 2.00 Bread
2 7.50 Cake
Example Output:
Bread
Cake
Cupcake
Key concepts
sortingdescending order
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