Dsa
Sorting
Warm-up
Sort Movie Release Years
You need to help a movie database system sort movies by their release years. Write a program that sorts a list of movies in ascending order based on their release years. If two movies have the same release year, sort them alphabetically by movie title.
Input:
The first line contains an integer M, the number of movies. The next M lines each contain a movie title (a string) followed by the release year (an integer).
Output:
Print the sorted list of movies with their release years, one per line, in the format 'Title Year'.
Example:
Input:
4
Inception 2010
Interstellar 2014
The Matrix 1999
Avatar 2009
Output:
The Matrix 1999
Avatar 2009
Inception 2010
Interstellar 2014
Key concepts
sortingtuplesbasic
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