A backup tool holds n file labels, each a non-empty string of lowercase English letters and digits (no spaces). Sort the labels so that a shorter label comes before a longer one. Labels of the same length are ordered lexicographically (by ordinary character comparison, where digits 0-9 come before letters a-z). Duplicate labels are allowed and simply appear together.
Line 1: an integer n.
The next n tokens (each on its own line) are the file labels.
The n labels, one per line, in the sorted order described above.
Example 1
Input
4 banana fig kiwi apple
Expected
fig kiwi apple banana
Explanation
Sorted by length: fig (3), kiwi (4), apple (5), banana (6).
Example 2
Input
3 bob ada cat
Expected
ada bob cat
Explanation
All length 3, so they are ordered alphabetically: ada, bob, cat.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →