[C++] beats 100% , sliding window + rolling hash
\nstatic long MOD = 1e9 + 7;\nclass Solution {\npublic:\n    \n    long powMod(long x,int y) {   \n        long res=1;\n        while (y>0) \n        { \n      
```\nstatic long MOD = 1e9 + 7;\nclass Solution {\npublic:\n    \n    long powMod(long x,int y) {   \n        long res=1;\n        while (y>0) \n        { \n            if(y&1) \n                res=(res*x)%MOD; \n            y=y>>1;\n            x=(x*x)%MOD;   \n        } \n        return res; \n    } \n    \n    int maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n        unordered_map<long, int> freqMap;\n        int unique = 0;\n        int fa[26] = {};\n        long hash=0,Pow=powMod(53,minSize-1);\n        int start = 0;\n        int res = 0;\n        for(int i = 0; i<s.length(); i++){\n            if(++fa[s[i]-\'a\'] == 1) unique++;\n            if(i-start+1 > minSize) {\n                hash-=(s[start]-\'a\')*Pow;\n                if(--fa[s[start] - \'a\'] == 0)\n                    unique--;\n                start++;\n            }\n            hash=(hash*53+s[i]-\'a\')%MOD;\n            if(i-start+1 == minSize && unique <= maxLetters) {\n                res = max(res, ++freqMap[hash]);\n            }\n        }\n    \n        return res;\n    }\n};\n```
[]