Last active
March 30, 2024 23:27
-
-
Save ZakriaJanjua/a39270f47902cdfaa0ecfd4545a0f125 to your computer and use it in GitHub Desktop.
Counting Sort algorithm in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# defines the range of the numbers that will be input in the array | |
RANGE = 100 | |
def countingSort(arr): | |
# Write your code here | |
count = [0] * RANGE | |
result = [] | |
for i in arr: | |
count[i] += 1 | |
for idx, ele in enumerate(count): | |
if (idx * ele > 0): | |
result.extend([idx for i in range(ele)]) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@thechaak can you provide me the input