1338. Reduce Array Size to The Half
1338. Reduce Array Size to The Half
class Solution:
def minSetSize(self, arr: List[int]) -> int:
counter = Counter(arr)
heap = []
for k, v in counter.items():
heapq.heappush(heap, (-v, k))
acc = 0
count = 0
total = len(arr)
while acc < total // 2 and heap:
v, k = heapq.heappop(heap)
acc -= v
count += 1
return count