leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1481.cpp (506B)


      1 class Solution {
      2   public:
      3     int findLeastNumOfUniqueInts(const vector<int> &arr, int k) const {
      4         unordered_map<int, int> um;
      5         for (const int n : arr)
      6             um[n]++;
      7 
      8         static int count[100001];
      9         size_t sz = 0;
     10         for (const auto [_, cnt] : um)
     11             count[sz++] = cnt;
     12 
     13         sort(begin(count), begin(count) + sz);
     14         for (int i = 0; i < sz; i++) {
     15             k -= count[i];
     16             if (k < 0) return sz - i;
     17         }
     18 
     19         return 0;
     20     }
     21 };