Gary Lai
  • Home
  • About
  • Backtrack
Sign in Subscribe

1338. Reduce Array Size to The Half

Last updated on  Oct 30, 2025

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
Previous 1323. Maximum 69 Number
Next 1283. Find the Smallest Divisor Given a Threshold
Gary Lai © 2025
  • Sign up
Powered by Ghost