Names in Order
Return the names of names in alphabetical order, ignoring upper and lower case: "bob" comes before "Cleo", and "adam" before "Bob". Every name keeps its own spelling in the answer.
Names that are equal once case is ignored, like "amy" and "AMY", keep the order they had in names.
Example 1
names ["bob","Cleo","adam"]
returns ["adam","bob","Cleo"]
Without case the order is adam, bob, cleo. A plain sort would put "Cleo" first, because capital letters sort before small ones.
Example 2
names ["amy","AMY","Al"]
returns ["Al","amy","AMY"]
"Al" comes first. "amy" and "AMY" are equal without case, so they stay in their original order.
Example 3
names []
returns []
An empty list stays empty.
Constraints
0 <= len(names) <= 20- each name has
1to8English letters, in any mix of upper and lower case
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Sorting and searching problems
- Shortest Words FirstBeginner
- Sort by Last DigitBeginner
- Strictly Increasing CheckBeginner
- Top Three ValuesBeginner
- Where It LandsBeginner
- Widest Gap After SortingBeginner
- Binary SearchEasy
- Can Attend All MeetingsEasy