Dsa
Sorting
Warm-up
Sort Employees by Department
You are given a list of employee records, where each record consists of an employee's name and their department, separated by a comma. Sort the records first by department name and then by employee name within each department. Print the sorted records, one per line.
Example Input:
John Doe,Engineering
Anna Smith,Marketing
Bob Lee,Engineering
Charlotte Clark,Marketing
Example Output:
Anna Smith,Marketing
Charlotte Clark,Marketing
John Doe,Engineering
Bob Lee,Engineering
Key concepts
sortingdata-structuresdictionary
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