| leetcodeSolution to some Leetcode problems written in C++ | 
| git clone git://git.dimitrijedobrota.com/leetcode.git | 
| Log | Files | Refs | README | LICENSE | 
2958.cpp (431B)
    0 class Solution {
              1   public:
              2     int maxSubarrayLength(const vector<int> &nums, const int k) const {
              3         unordered_map<int, int> freq;
              4         const int n = size(nums);
              5         int res = 0, i = 0;
          
              7         for (int j = 0; j < n; j++) {
              8             freq[nums[j]]++;
              9             while (freq[nums[j]] > k)
             10                 freq[nums[i++]]--;
             11             res = max(res, j - i + 1);
             12         }
          
             14         return max(res, n - i);
             15     }
             16 };