Question bank › Sorting
Dsa Sorting Medium

Employee Sorting

Your company is reorganizing, and you need to sort a list of employees for a directory. Each employee has a name and an age. You need to sort the employees by age in ascending order. If two employees have the same age, their names should be sorted in reverse alphabetical order. Input consists of an integer N (the number of employees), followed by N lines with the employee's name and age separated by a comma. Output the sorted list in the format 'Name - Age'. Example Input: 4 Alice,30 Bob,25 Charlie,30 David,35 Example Output: Bob - 25 Charlie - 30 Alice - 30 David - 35

Key concepts

sortingstringsdictionaries

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.