SORT-P5

Passenger ages

Practice 5 of 6Sorting5 tests

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

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

5 tests, not run yet
Test results
#TestResultReads · time
1A few passengersNot run
2EmptyNot run
3All the sameNot run
4Input not changedNot run
51.5 million passengersNot run