Java - Two Pointers - 24 ms, faster than 96.92% - 41.3 MB, less than 7.04%
\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        Map<String, Integer> subStrCnts = new HashMap<>();\n  
```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        Map<String, Integer> subStrCnts = new HashMap<>();\n        int l = 0;\n        int maxCnt = 0;\n        int n = s.length();\n        char[] cs = s.toCharArray();\n        int[] cnts = new int[26];\n        int unique = 0;\n        for (int r = 0; r < n; ++r) {\n            if (cnts[cs[r] - \'a\']++ == 0) {\n                ++unique;\n            }\n            while (l <= r && (unique > maxLetters || r - l + 1 > minSize)) {\n                if (--cnts[cs[l++] - \'a\'] == 0) {\n                    --unique;\n                }\n            }\n            if (r - l + 1 >= minSize) {\n                String str = s.substring(l, r + 1);\n                subStrCnts.put(str, subStrCnts.getOrDefault(str, 0) + 1);\n                maxCnt = Math.max(maxCnt, subStrCnts.get(str));\n            }\n        }\n        return maxCnt;\n    }\n}\n```
[]