Skip to content

Commit

Permalink
Time: 107 ms (76.92%) | Memory: 71.6 MB (65.13%) - LeetSync
Browse files Browse the repository at this point in the history
  • Loading branch information
ShatilKhan committed Feb 16, 2024
1 parent d70fc96 commit 5f7441c
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @param {number[]} arr
* @param {number} k
* @return {number}
*/
var findLeastNumOfUniqueInts = function(arr, k) {
let mp = new Map();
for (let a of arr) {
mp.set(a, (mp.get(a) || 0) + 1);
}

let v = Array.from(mp.values());
let cnt = 0;
v.sort((a, b) => a - b);
for (let i = 0; i < v.length; i++) {
if (k > v[i]) {
k -= v[i];
v[i] = 0;
} else {
v[i] -= k;
k = 0;
}
if (v[i] !== 0) cnt++;
}
return cnt;
};

0 comments on commit 5f7441c

Please sign in to comment.