Dsa
Sorting
Easy
Sort Book Editions
You manage a library, and you have a list of book editions consisting of a title and its print year. You need to sort these editions by year, and by title for those published in the same year. Each edition is represented by a string in the format 'Title (Year)'. Your task is to read these editions, sort them accordingly, and print them in a single line separated by commas.
Input:
- The first line contains an integer N (1 ≤ N ≤ 100) indicating the number of editions.
- The next N lines each contain one edition string in the format 'Title (Year)'.
Output:
- A single line with the sorted editions, separated by commas.
Example:
Input:
3
The Great Gatsby (1925)
1984 (1949)
Brave New World (1932)
Output:
The Great Gatsby (1925), Brave New World (1932), 1984 (1949)
Key concepts
sortingarraysstrings
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