Java solution 29ms
Using an Integer to check number of characters in a string. Time: 30ms (beats 79%)\n\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int min
Using an Integer to check number of characters in a string. Time: 30ms (beats 79%)\n```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        int res = 0, n = s.length();\n        Map<String, Integer> map = new HashMap<>();\n        Integer b;\n\n        for (int i = 0; i < n - minSize + 1; i++) {\n            String sub = s.substring(i, i + minSize);\n            b = 0;\n            for (char c : sub.toCharArray()) {\n                b |= (1 << (c - \'a\'));\n            }\n            if (Integer.bitCount(b) > maxLetters) continue;\n            map.put(sub, map.getOrDefault(sub, 0) + 1);\n            res = Math.max(res, map.get(sub));\n        }\n        return res;\n    }\n}\n```\n\nSolution uses int array to check number of characters in a string. Time: 29 ms (beats 80%).\n\n```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        int res = 0, n = s.length();\n        Map<String, Integer> map = new HashMap<>();\n        int[] arr = new int[26];\n        int count = 0; //count diff character in array\n        for (int i = 0; i < n - minSize + 1; i++) {\n            String sub = s.substring(i, i + minSize);\n            if (i == 0) {\n                for (char c : sub.toCharArray()) {\n                    arr[c - \'a\']++;\n                    if (arr[c - \'a\'] == 1) count++;\n                }\n            } else {\n                int l = s.charAt(i - 1) - \'a\';\n                int r = sub.charAt(minSize - 1) - \'a\';\n                arr[l]--;\n                if (arr[l] == 0) count--;\n                arr[r]++;\n                if (arr[r] == 1) count++;\n            }\n\n            if (count > maxLetters) continue;\n            map.put(sub, map.getOrDefault(sub, 0) + 1);\n            res = Math.max(res, map.get(sub));\n        }\n        return res;\n    }\n}\n```
[]