Question bank › Sorting
Dsa Sorting Easy

Sort Product Sales

You are analyzing sales data for different products. Each product has a name and a quantity sold. Your task is to sort the products first by quantity sold in descending order, and by name in alphabetical order for products with the same quantity. Input: - The first line contains an integer N (1 ≤ N ≤ 100) indicating the number of products. - The next N lines each contain a product name and quantity sold separated by a space. Output: - A single line with the sorted products in the format 'Product Name Quantity', separated by commas. Example: Input: 4 Laptop 150 Phone 300 Tablet 150 Desktop 100 Output: Phone 300, Laptop 150, Tablet 150, Desktop 100

Key concepts

sortingtupleslists

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.