Least Number of Unique Integers after K Removal

Medium Topics Company Tags

Remove exactly k elements from arr. Return the smallest number of distinct integer values that can remain. Removing an element removes only that occurrence, and the removed positions do not need to be consecutive.

Example 1:

Input: arr = [1,1,2,3]
k = 2

Output: 1

Explanation: Remove the single occurrences of 2 and 3. Only the value 1 remains, so the answer is 1.

Example 2:

Input: arr = [7,7,8]
k = 0

Output: 2

Explanation: No elements may be removed. The remaining distinct values are 7 and 8, giving 2.

Example 3:

Input: arr = [4,5]
k = 2

Output: 0

Explanation: Remove both elements. The empty array contains zero distinct values.

Constraints:

  • 1 <= arr.length <= 100000
  • 1 <= arr[i] <= 1000000000
  • 0 <= k <= arr.length


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.