Counting Sort 1

  • + 1 comment

    A couple Python solutions:

    Fun one liner:

    def countingSort(arr):
        return [arr.count(i) for i in range(100)]
    

    Not very optimal, O(n^2) time complexity

    Better but more verbose solution for O(n) time complexity:

    def countingSort(arr):
        counts = [0 for i in range(100)]
        for n in arr:
            counts[n] += 1
        return [counts[i] for i in range(100)]