Problems > Shortest Words First

Shortest Words First

Difficulty: 1000 2000 ms 128 MB

strings sorting

Sort the words by length; equal-length words go alphabetically.

Input: one line with words separated by single spaces.

Output: the sorted words on one line.

Constraints:

  • 1 to 200 lowercase words

Sample Tests

Input 1
banana kiwi apple fig
Output 1
fig kiwi apple banana
Input 2
bb aa
Output 2
aa bb

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.