Java - Beats 99.6% - Count Sort // with comments
\nclass Solution {\n    \n    // Count Sort\n    public int[] sortArray(int[] arr) {\n        int max = Integer.MIN_VALUE;\n        int min = Integer.MAX_VALUE;
```\nclass Solution {\n    \n    // Count Sort\n    public int[] sortArray(int[] arr) {\n        int max = Integer.MIN_VALUE;\n        int min = Integer.MAX_VALUE;\n        for (int i=0;i<arr.length;++i) {\n          max = Math.max(max, arr[i]);\n          min = Math.min(min, arr[i]);\n        }\n        \n        int []farr = new int[max-min+1];\n        int []ans = new int[arr.length];\n\n        // collecting the frequencies\n        for(int i=0;i<arr.length;++i) \n          farr[arr[i]-min]++;\n\n        // convert frequencies to prefix sum array\n        for(int i=1;i<farr.length;++i) \n          farr[i] += farr[i-1];\n\n        // fill the ans array from farr\n        for(int i=arr.length-1;i>=0;--i) {\n          int val = arr[i];\n          int pos = farr[val-min];\n          ans[pos-1] = val;\n          farr[val-min]--;\n        }\n        \n        return ans;\n    }\n}\n```
['Sorting', 'Java']