Given an array of integers&nbsp;arr&nbsp;and an integer k.&nbsp;Find the least number of unique integers&nbsp;after removing exactly k elements.




&nbsp;
Example 1:

Input: arr = [5,5,4], k = 1
Output: 1
Explanation: Remove the single 4, only 5 is left.

Example 2:

Input: arr = [4,3,1,1,3,3,2], k = 3
Output: 2
Explanation: Remove 4, 2 and either one of the two 1s or three 3s. 1 and 3 will be left.

&nbsp;
Constraints:


	1 &lt;= arr.length&nbsp;&lt;= 10^5
	1 &lt;= arr[i] &lt;= 10^9
	0 &lt;= k&nbsp;&lt;= arr.length

from heapq import heappop, heapify



class Solution:

    def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:

        counter = collections.Counter(arr)

        min_heap = [(count, num) for num, count in counter.items()]



        heapify(min_heap)



        while k > 0:

            count, num = min_heap[0]



            if count > k:

                break



            heappop(min_heap)

            k -= count



        return len(min_heap)
class Solution {
    public int findLeastNumOfUniqueInts(int[] arr, int k) {
        Map<Integer,Integer> freqMap = new HashMap<>();
        for(int a: arr) freqMap.put(a, freqMap.getOrDefault(a,0)+1);
        PriorityQueue<Integer> pq = new PriorityQueue<>((i1,i2)->Integer.compare(freqMap.get(i1), freqMap.get(i2)));
        pq.addAll(freqMap.keySet());
        while(k>0 && !pq.isEmpty()){
            int element = pq.poll();
            int toBeDeleted = Math.min(k,freqMap.get(element));
            k-=toBeDeleted;
            if(toBeDeleted<freqMap.get(element)) 
                pq.add(element);
        }
        return pq.size();
    }
}
class Solution {

public:

    int findLeastNumOfUniqueInts(vector<int>& arr, int k) {

        int ans;

        unordered_map<int,int> mp;

        for(int i=0; i<arr.size(); i++){

            mp[arr[i]]++;

        }



        priority_queue< int, vector<int>, greater<int>> pq;

        for(auto it : mp){

            pq.push(it.second);

        }



        while(k>0){

           k-= pq.top();   

           if(k>=0){

              pq.pop(); 

           }

        }

        return pq.size();

    }

};
var findLeastNumOfUniqueInts = function(arr, k) {
    var hsh = {};
    var instance = {};  // store set with index # of occurence
    var count = 0;
    for (var i = 0; i < arr.length; i++)
    {
        if (hsh[arr[i]] == null)
        {
            count ++;
            hsh[arr[i]] = 1;
            if (instance[1] == null)
            {
                var intro = new Set();
                intro.add(arr[i]);
                instance[1] = intro;
            }
            else
            {
                instance[1].add(arr[i]);
            }
        }
        else
        {
            hsh[arr[i]] ++;
            var numTimes = hsh[arr[i]];
            instance[numTimes - 1].delete(arr[i]);
            
            if (instance[numTimes] == null)
            {
                instance[numTimes] = new Set();
                instance[numTimes].add(arr[i]);
            }
            else
            {
                instance[numTimes].add(arr[i]);
            }
        }
    }
    
    var removenum = 0;
    
    for (key in instance)
    {
        var instanceKey = instance[key].size;
        if (k == 0)
        {
            break;
        }
        else if (k >= key*instanceKey)
        {
            k -= key*instanceKey;
            count -= instanceKey;
        }
        else
        {
            count -= Math.floor(k/key);
            break;
        }
        
    }
    return count;
};
Least Number of Unique Integers after K Removals