I'm having a difficult time understanding where/why my solution fails for a Counting Sort function. It works for some variations of arr, but not all.
I ran through the correct solution and can understand how it works, but I'm still lost as to why mine does not. I've been trying to figure it out for some time now. Any help/insight is very much appreciated!
Note: arr is an array of integers.
My function:
def countingSort(arr):
fArray = [0] * 100
for i in range(len(arr)):
fArray[i] = arr.count(i)
return fArray
The correct solution:
def countingSort(arr):
fArray = [0] * 100
for i in range(len(arr)):
fArray[arr[i]] += 1
return fArray