Counting Sort 1

Sort by

recency

|

464 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

    Here is my simple Python solution!

    def countingSort(arr):
        frequency = [0 for i in range(100)]
        for num in arr:
            frequency[num] += 1
        return frequency
    
  • + 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
    

    `