Reformat · Medium
Sort by surname
A list of full names, one per line.
Task
Write a prompt that sorts the names by surname (the last word).
Output format
one full name per line
- A–Z by surname, ignoring capitals.
- Same surname: sort by first name.
- Write each name exactly as given.
Your prompt must contain {input}: it is replaced by each test case, just like the hidden tests in a hiring test.
Sample case 1
Input
Maya Lee Ali Khan Tom Brown
Output
Tom Brown Ali Khan Maya Lee
Sample case 2
Input
Zoe Adams Ben Adams
Output
Ben Adams Zoe Adams
There are 4 test cases in all; the others are like hidden tests: work out what tricky inputs they might use!