Dsa
Sorting
Easy
Sort Emails by Domain
You have a list of email addresses. Your task is to sort the email addresses based on their domain names. If two email addresses share the same domain, sort them alphabetically by their local part.
Input format:
- The first line contains an integer n, the number of email addresses.
- The next n lines each contain one email address.
Output format:
- Print the sorted email addresses, each on a new line.
Example input:
3
john@example.com
jane@example.com
alice@test.com
Output:
jane@example.com
john@example.com
alice@test.com
Key concepts
sortingstringsarrays
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