Dsa
Sorting
Easy
Employee Salaries
You are given a list of employees with their names and salaries. Your task is to sort these employees by their salaries in descending order. If two employees have the same salary, sort them by their names in ascending order.
Input format:
- The first line contains an integer n (1 <= n <= 1000), the number of employees.
- Each of the next n lines contains a string name followed by an integer salary (0 <= salary <= 100000).
Output format:
- Print the sorted employee names and salaries, each on a new line in the format 'name salary'.
Example:
Input:
3
Alice 50000
Bob 60000
Alice 60000
Output:
Alice 60000
Bob 60000
Alice 50000
Key concepts
sortingdictionariestuples
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