Dsa
Sorting
Easy
Student Course Enroller
You are tasked with organizing a set of student enrollments in different courses. Each enrollment includes a student's name and the course they are enrolled in. Sort the list of enrollments first by course name in ascending order, then by student name in ascending order.
Input format:
The first line contains an integer S (1 <= S <= 1000) — the number of enrollments.
The next S lines contain a student's name (a string) and a course name (a string) separated by a space.
Output format:
Print the sorted list of enrollments, each on a new line in the format: 'student_name course_name'.
Example:
Input:
3
Alice Math
Bob Science
Charlie Math
Output:
Alice Math
Charlie Math
Bob Science
Key concepts
sortinglistsdictionary
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