Least Number of Unique Integers after K Removals LeetCode solution in C++

1
class Solution {
2
public:
3
int findLeastNumOfUniqueInts(vector<int> &arr, int k) {
4
int ans;
5

6
unordered_map<int, int> mp;
7

8
for (int i = 0; i < arr.size(); i++) {
9
mp[arr[i]]++;
10
}
11

12
priority_queue<int, vector<int>, greater<int>> pq;
13

14
for (auto it : mp) {
15
pq.push(it.second);
16
}
17

18
while (k > 0) {
19
k -= pq.top();
20

21
if (k >= 0) {
22
pq.pop();
23
}
24
}
25

26
return pq.size();
27
}
28
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0