Dsa
Sorting
Hard
Custom Object Sorting
Given a list of objects representing books, sort them by publication year ascending. If two books were published in the same year, sort them by title in ascending order. Each book has a title (a string) and a publication year (an integer). Your input will consist of multiple lines, where each line contains a title followed by a year, separated by a comma. Output the sorted list of books, one per line in the same format.
Example Input:
'War and Peace,1869'
'Dune,1965'
'The Great Gatsby,1925'
'To Kill a Mockingbird,1960'
'1984,1949'
Example Output:
'War and Peace,1869'
'The Great Gatsby,1925'
'1984,1949'
'To Kill a Mockingbird,1960'
'Dune,1965'
Key concepts
sortingcustom-comparisonobjects
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