The problem
A count of all passengers lists each one’s age, a whole number from 0 to 150. Return a new list of the ages in order, smallest first. sorted() and .sort() are switched off, and a comparison sort in Python is too slow for one and a half million ages.
sort_ages([34, 7, 61, 7, 0, 34, 150])
# [0, 7, 7, 34, 34, 61, 150]
Limits
- Up to 1,500,034 ages.
Builds on SORT-6 Counting and radix sort.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
5 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | A few passengers | Not run | |
| 2 | Empty | Not run | |
| 3 | All the same | Not run | |
| 4 | Input not changed | Not run | |
| 5 | 1.5 million passengers | Not run |