<p>Given an array of integers&nbsp;<code>arr</code>&nbsp;and an integer <code>k</code>.&nbsp;Find the <em>least number of unique integers</em>&nbsp;after removing <strong>exactly</strong> <code>k</code> elements<b>.</b></p>

<ol>
</ol>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input: </strong>arr = [5,5,4], k = 1
<strong>Output: </strong>1
<strong>Explanation</strong>: Remove the single 4, only 5 is left.
</pre>
<strong class="example">Example 2:</strong>

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

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= arr.length&nbsp;&lt;= 10^5</code></li>
	<li><code>1 &lt;= arr[i] &lt;= 10^9</code></li>
	<li><code>0 &lt;= k&nbsp;&lt;= arr.length</code></li>
</ul>
class Solution {
public:
    void print_vi(const vector<int> &vi) {
        cout << "{ ";
        for (int i : vi) {
            cout << i << ", ";
        }
        cout << '}' << endl;
    }
    void print_umii(const unordered_map<int, int> &umii) {
        cout << "{ ";
        for (const auto [a, b] : umii) {
            cout << '(' << a << ':' << b << ") ";
        }
        cout << '}' << endl;
    }
    int findLeastNumOfUniqueInts(vector<int>& arr, int k) {
        unordered_map<int, int> numToOcc;
        int maxOcc = 0;
        for (int num : arr) {
            numToOcc[num]++;
            maxOcc = max(maxOcc, numToOcc[num]);
        }
        print_umii(numToOcc);
        vector<int> occToUct(maxOcc + 1);
        for (const auto [num, occ] : numToOcc) {
            occToUct[occ]++;
        }
        print_vi(occToUct);
        int occ = 1;
        while (occ < occToUct.size()) {
            if (occToUct[occ] == 0) {
                occ++;
                continue;
            }
            if (occ > k) break;
            k -= occ;
            occToUct[occ]--;
        }
        print_vi(occToUct);
        int uctTotal = 0;
        for (int uct : occToUct) {
            uctTotal += uct;
        }
        return uctTotal;
    }
};
63800