Counting Sort 2

  • + 0 comments

    My Python3 solution:

    def countingSort(arr):
        idx_arr=(max(arr)+1)*[0]
        sorted_arr=[]
        
        for i in arr:
            idx_arr[i]+=1
        
        for i in range(len(idx_arr)):
            sorted_arr=sorted_arr + idx_arr[i]*[i]
        
        return sorted_arr