The Reduce Array Size to The Half problem asks for the minimum number of unique integer values to remove such that the remaining array is at most half the original size. This coding problem uses frequency-based greedy selection — remove the most frequent elements first. The array, hash table, sorting, heap, and greedy interview pattern is the core.
Akuna Capital and Meta ask this because greedy selection by frequency is the optimal strategy: removing the most frequent element removes the most occurrences per "slot" used. It validates understanding of the greedy optimality proof.
Frequency sort + greedy greedy selection. Count frequencies of all values. Sort frequencies in descending order. Greedily remove the most frequent values first, accumulating the count of removed elements. Stop when removed ≥ n/2.
arr=[3,3,3,3,5,5,5,2,2,7,1,1,1,4,1,6]. n=16. Target remove ≥ 8. Frequencies: {3:4, 5:3, 1:4, 2:2, 7:1, 4:1, 6:1}. Sorted desc: [4,4,3,2,1,1,1].
Reduce Array Size to The Half is a straightforward greedy: remove most frequent first. The proof of optimality: any other ordering removes fewer total elements per unique value used. Practice similar "minimum removals to satisfy size constraint" problems. The max-heap or sorted-desc frequency approach is the standard solution.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values | Medium | Solve | |
| Distant Barcodes | Medium | Solve | |
| Task Scheduler | Medium | Solve | |
| Mice and Cheese | Medium | Solve | |
| Hand of Straights | Medium | Solve |