Least Number of Unique Integers after K Removals

Given an array of integers arr and an integer k, remove exactly k elements. Return the least number of unique integers that can be left in the array.

30:00

Least Number of Unique Integers after K Removals
medium
Free written solution
Topics
Companies

Given an array of integers arr and an integer k, remove exactly k elements. Return the least number of unique integers that can be left in the array.

Example 1:
Input: {"arr":[5,5,4],"k":1}
Output: 1
Constraints:
  • 1≤arr.length≤1051 \leq \text{arr.length} \leq 10^5

  • 1≤arr[i]≤1091 \leq \text{arr}[i] \leq 10^9

  • 0≤k≤arr.length0 \leq k \leq \text{arr.length}

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"arr":[5,5,4],"k":1}

Remove exactly k = 1 of the 3 elements so as few distinct values as possible survive.

arr

5

5

4

one pile per value

height = copies

no piles yet

removal budget

k = 1 of 1

distinct values left

0

Variables
VariableValue
k1
remaining0
DepthFunction Call
Stack empty
0/8