Dsa
Sorting
Warm-up
Sort Employee Records
You are managing employee records and need to sort them by their last names. Write a program that sorts a list of employees in alphabetical order based on their last names. If two employees have the same last name, sort them by their first names.
Input:
The first line contains an integer E, the number of employees. The next E lines each contain an employee's first name (a string) and last name (a string).
Output:
Print the sorted list of employees in the format 'FirstName LastName'.
Example:
Input:
3
John Doe
Jane Smith
Alice Doe
Output:
John Doe
Alice Doe
Jane Smith
Key concepts
sortingrecordsbasic
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