---
title: "1338. Reduce Array Size to The Half"
url: "https://laigary.com/interview/coding/1338-reduce-array-size-to-the-half"
type: "note"
section: "coding"
date: "2025-10-30"
updated: "2025-10-30"
tags: ["Greedy", "Heap", "Hash Table"]
---

# 1338. Reduce Array Size to The Half

[1338\. Reduce Array Size to The Half](https://leetcode.com/problems/reduce-array-size-to-the-half/)

```python
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
```
