File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 170
170
1472|[ Design Browser History] ( ./1472-design-browser-history.js ) |Medium|
171
171
1475|[ Final Prices With a Special Discount in a Shop] ( ./1475-final-prices-with-a-special-discount-in-a-shop.js ) |Easy|
172
172
1480|[ Running Sum of 1d Array] ( ./1480-running-sum-of-1d-array.js ) |Easy|
173
+ 1481|[ Least Number of Unique Integers after K Removals] ( ./1481-least-number-of-unique-integers-after-k-removals.js ) |Medium|
173
174
1486|[ XOR Operation in an Array] ( ./1486-xor-operation-in-an-array.js ) |Easy|
174
175
1492|[ The kth Factor of n] ( ./1492-the-kth-factor-of-n.js ) |Medium|
175
176
1496|[ Path Crossing] ( ./1496-path-crossing.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 1481. Least Number of Unique Integers after K Removals
3
+ * https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given an array of integers arr and an integer k. Find the least number of
7
+ * unique integers after removing exactly k elements.
8
+ */
9
+
10
+ /**
11
+ * @param {number[] } arr
12
+ * @param {number } k
13
+ * @return {number }
14
+ */
15
+ var findLeastNumOfUniqueInts = function ( arr , k ) {
16
+ const map = new Map ( ) ;
17
+ arr . forEach ( n => map . set ( n , map . has ( n ) ? map . get ( n ) + 1 : 1 ) ) ;
18
+
19
+ const sorted = [ ...map . values ( ) ] . sort ( ( a , b ) => a - b ) ;
20
+ while ( k && sorted . length && sorted [ 0 ] <= k ) {
21
+ k -= sorted [ 0 ] ;
22
+ sorted . shift ( ) ;
23
+ }
24
+
25
+ return sorted . length ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments