Dsa
Sorting
Easy
Fruit Basket Sort
You have a collection of fruit names with their quantities in a basket. Your task is to sort them in descending order based on quantity. If two fruits have the same quantity, sort them alphabetically by their names. Input consists of multiple lines with each line containing a fruit name followed by the quantity, separated by a space. Output should be the sorted list with fruit names and quantities, one per line.
Example:
Input:
Apple 10
Banana 5
Cherry 10
Output:
Apple 10
Cherry 10
Banana 5
Key concepts
sortinglists
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