Counting Sort 1

Sort by

recency

|

463 Discussions

|

  • + 0 comments

    Here is my c++ solution, you can watch the explanation here : https://youtu.be/snADwNvEEcM

    vector<int> countingSort(vector<int> arr) {
        vector<int> count(100, 0);
        for(int i = 0; i < arr.size(); i++) count[arr[i]]++;
        return count;
    }
    
  • + 0 comments
    public static List<int> countingSort(List<int> arr)
    {
        var countMap = arr.GroupBy(n => n)
                        .OrderBy(g => g.Key)
                        .ToDictionary(g => g.Key, g => g.Count());
    
        List<int> zeros = Enumerable.Repeat(0, 100).ToList();
    
        for (int i = 0; i < zeros.Count; i++)
        {
            if (countMap.ContainsKey(i))
            {
                zeros[i] = countMap.GetValueOrDefault(i); 
            }
        }
    
        return zeros;
    }
    
  • + 0 comments

    My answer in typescript, simple

    function countingSort(n: number, arr: number[]): number[] {
        let arr_count = Array(100).fill(0)
    
        for (let i = 0; i < arr.length; i++) arr_count[arr[i]]++
    
        return arr_count;
    }
    
  • + 1 comment

    UIUA Solution

    (/+:x)⇡⧻x
    

    `

  • + 0 comments

    My C code 😁😎🐦‍🔥

    int* countingSort(int arr_count, int* arr, int* result_count) {
        int* result = (int*)calloc(100,sizeof(int));
        *result_count = 100;
        
        for(int i = 0;i < arr_count;i++){
            result[arr[i]]++;
        }
        return result;
    }