Leetcode 1604 Solution
This article provides solution to leetcode question 1604 (least-number-of-unique-integers-after-k-removals)
Access this page by simply typing in "lcs 1604" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals
Solution
class Solution:
def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:
cnts = collections.defaultdict(int)
for v in arr:
cnts[v] += 1
q = []
for v in cnts.values():
heapq.heappush(q, v)
while q:
v = heappop(q)
if k >= v:
k -= v
else:
return len(q) + 1
return 0