Counting Sort 1

  • + 0 comments

    !/bin/python3

    import math import os import random import re import sys

    def countingSort(arr, n): count = [0] * 100 # Fixed-size array of 100 elements

    for num in arr:
        count[num] += 1  # Count occurrences efficiently
    
    return count
    

    if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')

    n = int(input().strip())
    
    arr = list(map(int, input().rstrip().split()))
    
    result = countingSort(arr,n)
    
    fptr.write(' '.join(map(str, result)))
    fptr.write('\n')
    
    fptr.close()