Counting Sort 1

  • + 0 comments

    My Java solution with o(n) time complexity and o(1) space complexity:

    public static List<Integer> countingSort(List<Integer> arr) {
            // init freq array
            int[] freqArr = new int[100];
            
            //update freq for each val
            for(int element : arr) freqArr[element]++;
            
            //return int array converted into Integer list
            return Arrays.stream(freqArr)
                .boxed()
                .collect(Collectors.toList());
        }