FunctionRacerProblemsRace

Shortest Words First

BeginnerSorting and searchingPython, JavaScript, TypeScript, Java, C++

Return a new list with the words of words ordered from shortest to longest. Words of the same length keep the order they had in words, so the sort must be stable. Do not change words.

An empty list gives an empty list.

Example 1

words ["pear","fig","banana","kiwi"]
returns ["fig","pear","kiwi","banana"]

fig has 3 letters, pear and kiwi have 4 (pear came first), banana has 6.

Example 2

words ["bb","a","cc","d"]
returns ["a","d","bb","cc"]

a and d have one letter and keep their order; bb and cc keep theirs.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Sorting and searching problems