Skip to content

Commit 15c9190

Browse files
committed
✨ least number of unique integers after k removals
1 parent 692ae64 commit 15c9190

File tree

1 file changed

+21
-0
lines changed
  • src/1481-least-number-of-unique-integers-after-k-removals

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {number[]} arr
3+
* @param {number} k
4+
* @return {number}
5+
*/
6+
var findLeastNumOfUniqueInts = function (arr, k) {
7+
const hash = {};
8+
for (let i = 0; i < arr.length; i++) {
9+
hash[arr[i]] = ~~hash[arr[i]] + 1;
10+
}
11+
12+
const values = Object.values(hash).sort((x, y) => x - y);
13+
let count = 0;
14+
15+
while (values[count] <= k) {
16+
k -= values[count];
17+
count++;
18+
}
19+
20+
return values.length - count;
21+
};

0 commit comments

Comments
 (0)