Equalize the Array

Equalize the Array

 public static int equalizeArray(List<Integer> arr) {
            HashMap<Integer, Integer> frequ = new HashMap<>();
        for (Integer a : arr)
            frequ.put(a, frequ.getOrDefault(a, 0) + 1);

        int maxFrequ = Integer.MIN_VALUE;
        for (Integer a : frequ.keySet()) {
            maxFrequ = Integer.max(maxFrequ, frequ.get(a));
        return arr.size() - maxFrequ;


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s