Least Number of Unique Integers after K Removals LeetCode solution in Python

1
from heapq import heappop, heapify
2

3

4
class Solution:
5

6
def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:
7

8
counter = collections.Counter(arr)
9

10
min_heap = [(count, num) for num, count in counter.items()]
11

12
heapify(min_heap)
13

14
while k > 0:
15

16
count, num = min_heap[0]
17

18
if count > k:
19

20
break
21

22
heappop(min_heap)
23

24
k -= count
25

26
return len(min_heap)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0