• + 0 comments

    Python solution with O(n) complexity and without using collections library:

    def equalize_array(arr):
        count = {}
        for el in arr:
            if el in count:
                count[el] += 1
            else:
                count[el] = 1
        # Find the maximum frequency
        max_count = 0
        for value in count.values():
            if value > max_count:
                max_count = value
        # Calculate the number of elements to remove
        return len(arr) - max_count