Dsa
Sorting
Medium
Region Sales Analysis
You have sales data by region, where each region has a name and a total sales amount. Your task is to sort the regions by total sales in descending order. If two regions have the same sales, sort them alphabetically by region name.
Input:
- The first line contains an integer n (1 <= n <= 1000).
- The next n lines contain region_name (a string) and total_sales (a float).
Output:
- Print each region in the sorted order in the format 'region_name total_sales'.
Example:
Input:
3
West 12000.50
East 15000.00
North 12000.50
Output:
East 15000.00
North 12000.50
West 12000.50
Key concepts
sortingsales datagrouping
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