Java O(n) Solution
```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        Map res = new HashMap<>();\n        int n = s.lengt
```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        Map<String, Integer> res = new HashMap<>();\n        int n = s.length(), resCnt = 0;\n        if(minSize > n) return 0;\n        for(int i = 0; i < n; i++){            \n            Map<Character, Integer> map = new HashMap<>();\n            for(int distNum = 0, j = 0; j < maxSize; j++){\n                if(i + j >= n) break;\n                map.put(s.charAt(i + j), map.getOrDefault(s.charAt(i + j), 0) + 1);\n                if(map.get(s.charAt(i + j)) == 1) distNum++;\n                if(distNum > maxLetters) break;\n                if(j >= minSize - 1)\n                    res.put(s.substring(i, i + j + 1), res.getOrDefault(s.substring(i, i + j + 1), 0) + 1);       \n            }\n        }\n        for(String str: res.keySet()){            \n            if(res.get(str) > resCnt)\n                resCnt = res.get(str);\n        }\n        return resCnt;        \n    }\n}\n
[]