Question bank › Sorting
Dsa Sorting Medium

Group Sort

You are given a list of people represented by tuples with (name, age). Your task is to sort this list firstly by age, and then by name alphabetically for persons of the same age. Input: - The first line contains an integer n (1 <= n <= 1000), the number of people. - The next n lines contain the name and age (name is a string with no spaces, age is an integer). Output: - Print each person in the sorted order. Each person should be printed on a new line in the format 'name age'. Example: Input: 3 Alice 30 Bob 25 Charlie 30 Output: Bob 25 Alice 30 Charlie 30

Key concepts

sortinggroupingdata structures

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 Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.