• + 38 comments

    O(n) solution

    public static int minDeletions(int[] a) {
        int max = 1;
        Map<Integer, Integer> nums = new HashMap<>();
        for (int i : a)
            if (!nums.containsKey(i))
                nums.put(i, 1);
            else {
                nums.put(i, nums.get(i) + 1);
                if (max < nums.get(i))
                    max = nums.get(i);
            }
        return a.length - max;
    }