FunctionRacerProblemsRace

Sort by Last Digit

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

Return the numbers of nums ordered by their last digit, from 0 to 9. Numbers with the same last digit keep the order they had in nums, so the sort must be stable.

For example, [21, 13, 40, 31] becomes [40, 21, 31, 13]: 21 and 31 both end in 1, and 21 came first.

Example 1

nums [21,13,40,31]
returns [40,21,31,13]

40 ends in 0 and goes first. 21 and 31 end in 1 and keep their order. 13 ends in 3.

Example 2

nums [5,15,25]
returns [5,15,25]

All three end in 5, so nothing moves.

Example 3

nums []
returns []

An empty list stays empty.

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