[Java] Sliding window solution O(n) with comment.
\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        int[] letterCount = new int[26];  /*count letter*/ \n 
```\nclass Solution {\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        int[] letterCount = new int[26];  /*count letter*/ \n        char[] strs = s.toCharArray();\n        Map<String,Integer> stringCount = new HashMap<>();  /*count specific string satisfy requirement.*/\n        int start = 0, end = start + minSize - 1, letterTotal = 0, ans = 0; /*letterTotal stores current total number of distinct letter. */\n\t\t/*deal with the first string with minSize. */\n        for(int i = start; i <= end; i++){\n            if(letterCount[strs[i] - \'a\'] == 0) letterTotal++;\n            letterCount[strs[i] - \'a\']++;\n        }\n        if(letterTotal <= maxLetters){\n            stringCount.put(s.substring(start, end + 1), 1);\n            ans = 1;\n        }\n\t\t\n\t\t/*slide in one letter, slide out one letter, and check if the substring in the sliding window satisfy the requirement. */\n\t\t\n        end++;\n        while(end < s.length()){\n            if(letterCount[strs[end] - \'a\']++ == 0) letterTotal++;\n            if(letterCount[strs[start] - \'a\']-- == 1) letterTotal--;\n            start++;\n            if(letterTotal <= maxLetters){\n                String curStr = s.substring(start, end + 1);\n                stringCount.put(curStr, stringCount.getOrDefault(curStr, 0) + 1);\n                ans = Math.max(ans, stringCount.get(curStr));\n            }\n            end++;\n        }\n        return ans;\n    }\n}\n```
[]