• + 0 comments

    JAVA There are some solutions using streams, but maybe it will be more readable for somebody:

        public static int equalizeArray(List<Integer> arr) {
        //create a map to be able to count occurances
        HashMap<Integer, Integer> arrMap = new HashMap<>();
        
        for(int num : arr) {
            if(arrMap.containsKey(num)) {
                arrMap.put(num, arrMap.get(num) +1);
            } else {
                arrMap.put(num, 1);
            }
        }
        
        int max = 0;
        
        for(int valueOfArrMap : arrMap.values()) {
            if(valueOfArrMap >= max) max = valueOfArrMap;
        }
        
    return arr.size() - max;