Dsa
Sorting
Hard
Product Ranking
Given a list of products, each represented by a name and a rating, sort the products first by rating in descending order, and then by name in ascending order if the ratings are equal. Each line of input consists of 'product_name,rating'. Outputs should be the sorted list in the same format.
Example Input:
Apple,4.5
Banana,4.5
Cherry,4.7
Date,4.1
Elderberry,4.3
Example Output:
Cherry,4.7
Apple,4.5
Banana,4.5
Elderberry,4.3
Date,4.1
Key concepts
sortingrankingtuples
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