Java O(n) solution with comments
Here is O(n) solution with explaination.\n\n\npublic int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        \n\t// Map to store different st
Here is O(n) solution with explaination.\n\n```\npublic int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        \n\t// Map to store different strings and their freq\n\tMap<String, Integer> map = new HashMap<>();\n\tint res = 0;\n\n\t// we rotate a sliding window of minSize \n\t// because if "abc" is present in "abcabc" then "ab" will also be there.\n\tfor(int i = 0; i < s.length() - minSize + 1; i++){\n\n\t\tString str = s.substring(i, i+minSize);\n\n\t\t// check the substring does not contains distinct letters more than maxLetters\n\t\tif(isValid(str, maxLetters)){\n\n\t\t\t// Update frequency in map\n\t\t\tmap.put(str, map.getOrDefault(str, 0) + 1);\n\t\t\t// Continuously update res with most frequent element\n\t\t\tres = Math.max(map.get(str), res);\n\t\t}\n\t}\n\treturn res;\n}\n\nprivate boolean isValid(String str, int maxLetter){\n\tint[] freq = new int[26];\n\tint distinct = 0;\n\tfor(char c : str.toCharArray()){\n\t\tif(freq[c - \'a\']++ == 0) distinct++;\n\t}\n\treturn distinct <= maxLetter;\n}\n```
['Java']