Counting Sort 1

Sort by

recency

|

461 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

    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;
    }
    
  • + 0 comments

    def countingSort(arr): count_arr = [0]*100 for i in arr: count_arr[i] +=1 return count_arr

  • + 0 comments

    plese anyone guide me in this code where i am doing mistke public static List countingSort(List arr) { // Write your code here //find the max and min in the given list if(arr==null || arr.isEmpty()){ return new ArrayList<>(); }

     int max = arr.get(0);
        int min = arr.get(0);
        for (int num : arr) {
            if (num > max) {
                max = num;
            }
            if (num < min) {
                min = num;
            }
        }
     int range = max-min + 1;
         List<Integer>list= new ArrayList<>();
    
         for (int i = 0; i < range; i++) {
            list.add(0);
        }         // store the count of the element
         for (int num : arr) {
            list.set(num - min, list.get(num - min) + 1);
        }
         return list;