Question bank › Sorting
Dsa Sorting Easy

Book Sorting for Library

A library needs to organize its books based on the author's last name and then by the book title. You will receive multiple lines of input with each line containing the author's name followed by the book title, separated by a dash. Your objective is to sort the books first by the author's last name and then by the book title. The output should be the sorted list in the same format. Example: Input: Harper Lee - To Kill a Mockingbird George Orwell - 1984 Harper Lee - Go Set a Watchman Output: George Orwell - 1984 Harper Lee - Go Set a Watchman Harper Lee - To Kill a Mockingbird

Key concepts

sortingcomparator

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.