Dsa
Sorting
Medium
Custom Sort for Movie Ratings
You are tasked with implementing a custom sort for a list of movies based on their ratings. Each movie has a title and a rating, and you need to sort them in descending order based on their ratings. If two movies have the same rating, they should be sorted alphabetically by title in ascending order. Input will consist of an integer N (the number of movies), followed by N lines each containing the title of the movie and its rating separated by a comma. Output the sorted list of movies, each on a new line in the format 'Title (Rating)'.
Example Input:
4
Inception,8.8
Avatar,7.8
Titanic,7.8
The Dark Knight,9.0
Example Output:
The Dark Knight (9.0)
Inception (8.8)
Avatar (7.8)
Titanic (7.8)
Key concepts
sortingcomparisonstuples
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