Counting Sort

easy
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 5. Everything before it counts as cleared.

When values are small integers, sorting can beat O(n log n). Implement a stable counting_sort(items, key, max_key) where key(item) returns an integer in 0..max_key:

  1. count each key
  2. turn counts into starting positions (prefix sums)
  3. place items into the output in input order

Return a new list.

#sorting#linear-time2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Counting Sort · TechGradify