class Solution:
def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:
freq = sorted(Counter(arr).values())
n = len(freq)
for i in range(n):
if k >= freq[i]:
k -= freq[i]
else:
return n - i
return 0class Solution:
def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:
freq = Counter(arr)
heap = list(freq.values())
heapq.heapify(heap)
res = len(heap)
while k > 0 and heap:
f = heapq.heappop(heap)
if k >= f:
k -= f
res -= 1
return resclass Solution:
def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:
freq = Counter(arr)
freq_list = [0] * (len(arr) + 1)
for n, f in freq.items():
freq_list[f] += 1
res = len(freq)
for f in range(1, len(freq_list)):
remove = freq_list[f]
if k >= f * remove:
k -= f * remove
res -= remove
else:
remove = k // f
res -= remove
break
return res