C++ O(n)
Intuition\n1. We need to find all substrings that meet specific criteria. We can do it in O(n) using a rolling window approach.\n2. We can ignore maxSize - minS
#### Intuition\n1. We need to find all substrings that meet specific criteria. We can do it in O(n) using a rolling window approach.\n2. We can ignore `maxSize` - `minSize` substring will repeat the same or greater number of times.\n3. Since we process all matching substring, we can just use a hash map to count their occurrences.  \n#### C++ Solution\n```\nint maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n    int i = 0, j = 0, unique = 0, res = 0, cnt[26] = {};\n    unordered_map<string, int> m;\n    while (j < s.size()) {\n        if (++cnt[s[j++] - \'a\'] == 1) ++unique;\n        while (unique > maxLetters || j - i > minSize)\n            if (--cnt[s[i++] - \'a\'] == 0) --unique;\n        if (j - i == minSize)\n            res = max(res, ++m[s.substr(i, minSize)]);\n    }\n    return res;\n}\n```\n**Complexity Analysis**\n- Time: O(n); we process each character once. Strictly, the complexity is O(n * minSize) because we need to calculate hash for up to `n` strings of size `minSize`. However, we could have used a rolling hash approach instead.\n- Memory: O(n * minSize) for the hash map. This can be potentially reduced to O(n) if we store a rolling hash and indexes of substrings (to deal with dups in the end).
[]