Question bank › Sorting
Dsa Sorting Warm-up

Sort by Length

Create a program that reads a list of words from standard input and outputs them sorted by their lengths in ascending order. If two words have the same length, preserve their original order. Input format: - The first line contains an integer n (1 ≤ n ≤ 100). The second line contains n words separated by spaces. Output format: - A single line containing the words sorted by length, separated by spaces. Example: Input: 4 apple banana pie peach Output: pie apple peach banana

Key concepts

sortingstrings

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of Praxari's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.