Counting Sort 1

  • + 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;