168. Sort Words by Length
EasyCustom Sort
Sort the words by length (shortest first); words of equal length are sorted alphabetically.
Input format
Line 1: n Line 2: n lowercase words
Output format
The sorted words.
Example 1
Input
5 banana kiwi apple fig date
Output
fig date kiwi apple banana
Example 2
Input
1 hello
Output
hello
Constraints
1 ≤ n ≤ 10⁴
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…