Simple Sliding Window C++ Solution
This is a simple problem, which wants to find frequency of substrings of size in a range [minSize, maxSize] with unique characters count <= maxLetters.\n\nOne t
This is a simple problem, which wants to find frequency of substrings of size in a range `[minSize, maxSize]` with unique characters count ` <= maxLetters`.\n\nOne thing to note is that all substrings of with `size = minSize`, will always give maximum frequency. So, therefore I only need to check substrings of size `minSize` and keep their frequency. Finally, return the max frequency string.\n\n```\nclass Solution {\npublic:\n    int maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n        unordered_map<char, int> m;\n        \n        unordered_map<string, int> subs;\n        \n        int j = 0;\n        for(int i = 0; i < s.size(); i++)\n        {\n            m[s[i]]++;\n            int size = i - j + 1;\n            while(m.size() > maxLetters || size > minSize)\n            {\n                int start = j;\n                m[s[j]]--;\n                if(m[s[j]] == 0)\n                    m.erase(s[j]);\n                j++;\n                size--;\n            }\n            if(size >= minSize)\n            {\n                subs[ s.substr(j, size) ]++;\n            }\n        }\n        \n        int maxc = 0;\n        for(auto it = subs.begin(); it != subs.end(); it++)\n        {\n            maxc = max( maxc, it->second);\n        }\n        return maxc;\n    }\n};\n```
['Two Pointers', 'C', 'Sliding Window']