public int[] counting(int[] arr){
        int min = arr[0];
        int max = arr[0];
        for (int i = 1; i < arr.length; i++){
            min = min < arr[i] ? min : arr[i];
            max = max > arr[i] ? max : arr[i];
        }

        int buckets[] = new int[max - min + 1];
        int index = 0;
        for (int i = 0; i < arr.length; i++){
            index = arr[i] - min;
            buckets[index]++;
        }

        int res[] = new int[arr.length];
        for (int i = 0; i < res.length; i++){
            res[i] = -1;
        }

        for (int i = 0; i < arr.length; i++){
            index = arr[i] - min;
            int cnt = 0;
            for (int j = 0; j < index; j++){
                cnt += buckets[j];
            }
            while (res[res.length - 1 - cnt] != -1){
                cnt++;
            }
            res[res.length - 1 - cnt] = arr[i];
        }
        return res;
    }