Question bank › Sorting
Dsa Sorting Medium

Book Price Sorter

You are organizing a bookstore, and you need to sort a list of books based on their prices. Each book has a title and a price. You should sort the books by price in descending order. In case two books have the same price, sort them alphabetically by title. Input consists of an integer N (the number of books), followed by N lines containing the book title and price separated by a semicolon. Output the sorted list in the format 'Title - Price'. Example Input: 4 The Great Gatsby;10.99 1984;8.99 To Kill a Mockingbird;10.99 Brave New World;9.99 Example Output: The Great Gatsby - 10.99 To Kill a Mockingbird - 10.99 Brave New World - 9.99 1984 - 8.99

Key concepts

sortingfloatlists

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.