Question bank › Sorting
Dsa Sorting Easy

Employee Salary Sorter

You are given a list of employees, each with a name and a salary. Your task is to sort the employees based on their salary in descending order. If two employees have the same salary, they should be sorted by their names in ascending order. Input format: The first line contains an integer E (1 <= E <= 1000) — the number of employees. The next E lines consist of a name (a string) and a salary (a float), separated by a space. Output format: Print the sorted list of employees, each on a new line with their name followed by their salary in a fixed decimal format with two decimal places. Example: Input: 4 Alice 50000.50 Bob 60000.75 Charlie 50000.50 Dana 70000.00 Output: Dana 70000.00 Bob 60000.75 Alice 50000.50 Charlie 50000.50

Key concepts

sortingliststuples

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.