You're given an array of integers arr and an integer k. Your goal is to minimize the number of unique integers in the array by removing exactly k elements.
Think of it as a strategic elimination game: you have k removal operations, and you want to use them wisely to reduce the variety of numbers as much as possible. The key insight is that removing all occurrences of a number reduces the unique count by 1, while removing some (but not all) occurrences doesn't change the unique count at all.
For example, if you have [4,3,1,1,3,3,2] and can remove k=3 elements, you could remove one occurrence each of 4, 1, and 2, leaving [3,1,3,3] with 2 unique integers. But a better strategy would be to completely eliminate 4 and 2 (2 removals) and one occurrence of 1 (1 removal), leaving [3,1,3,3] with still 2 unique integers, or even better - remove 4, 2, and both 1's to get [3,3,3] with just 1 unique integer.
Input & Output
Constraints
- 1 β€ arr.length β€ 105
- 1 β€ arr[i] β€ 109
- 0 β€ k β€ arr.length
- k is always valid (you can always remove exactly k elements)