Dsa
Sorting
Medium
Book Sorting
You need to create a catalog of books, where each book is represented by its title and the author's name in the format 'Title,Author'. Your task is to sort the books by title in ascending order. In cases of ties, sort by author's name in ascending order. Print the sorted book list in the same format.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 1000), the number of books.
- The next n lines each contain a book record.
Output format:
- Print the sorted book records, one per line.
Example:
Input:
3
The Great Gatsby,F. Scott Fitzgerald
1984,George Orwell
To Kill a Mockingbird,Harper Lee
Output:
1984,George Orwell
The Great Gatsby,F. Scott Fitzgerald
To Kill a Mockingbird,Harper Lee
Key concepts
sortingstring manipulationtuples
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