<p>You are given an integer array <code>arr</code>. You can choose a set of integers and remove all the occurrences of these integers in the array.</p>

<p>Return <em>the minimum size of the set so that <strong>at least</strong> half of the integers of the array are removed</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr = [3,3,3,3,5,5,5,2,2,7]
<strong>Output:</strong> 2
<strong>Explanation:</strong> Choosing {3,7} will make the new array [5,5,5,2,2] which has size 5 (i.e equal to half of the size of the old array).
Possible sets of size 2 are {3,5},{3,2},{5,2}.
Choosing set {2,7} is not possible as it will make the new array [3,3,3,3,5,5,5] which has a size greater than half of the size of the old array.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr = [7,7,7,7,7,7]
<strong>Output:</strong> 1
<strong>Explanation:</strong> The only possible set you can choose is {7}. This will make the new array empty.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= arr.length &lt;= 10<sup>5</sup></code></li>
	<li><code>arr.length</code> is even.</li>
	<li><code>1 &lt;= arr[i] &lt;= 10<sup>5</sup></code></li>
</ul>

from heapq import _heapify_max, _heappop_max, _siftdown_max

class Solution:
    def minSetSize(self, array) -> int:
        num_to_freq_map = {}
        for i in range(0, len(array)):
            num = array[i]
            if (num in num_to_freq_map.keys()):
                num_to_freq_map[num] += 1
            else:
                num_to_freq_map[num] = 1
            
        freq_to_nums_map = {}
        for num in num_to_freq_map.keys():
            freq = num_to_freq_map[num]
            if (freq in freq_to_nums_map.keys()):
                freq_to_nums_map[freq].append(num)
            else:
                freq_to_nums_map[freq] = [num]
        
        half_count_nums = len(array) // 2
        sum_freq = 0
        ret_val = 0
        for freq in reversed(sorted(freq_to_nums_map.keys())):
            nums = freq_to_nums_map[freq]
            for num in nums:
                sum_freq += freq
                ret_val += 1
                if (sum_freq >= half_count_nums):
                    return ret_val

        return None

        

28396