Counting Sort

Sort an array of non-negative integers using counting sort for linear time performance.

Code

Algorithms
count = [0] * (max(arr) + 1)
for x in arr:
    count[x] += 1
result = []
for i, c in enumerate(count):
    result.extend([i] * c)
return result

Parameters

Array of integers

Server

More Python Snippets