35. How does counting sort achieve linear time?
MediumSorting
Technical
Show model answer
For integers in a small range [0, k], count how many times each value occurs, then rebuild the array in order. It runs in O(n + k) without comparisons. Radix sort applies a stable counting sort digit by digit to handle larger numbers.