Reduce Array Size to The Half
MediumGreedy
Decode it first. Clues, constraints, pattern and plan before any code.Pick a set of values and delete every occurrence of each picked value from arr. Return the minimum size of the set that removes at least half of the elements.
arr = [3, 3, 3, 3, 5, 5, 5, 2, 2, 7] → 2 (remove 3 and 5: 3 elements left)
arr = [7, 7, 7, 7, 7, 7] → 1
arr = [1, 2, 3, 4] → 2Constraints
2 <= arr.length <= 10^5arr.lengthis even.1 <= arr[i] <= 10^5