Simple Java Slide Window Using HashMap
\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        int left = 0, res = 0;\n        Map<Character, Integer> map = new HashMa
```\n    public int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        int left = 0, res = 0;\n        Map<Character, Integer> map = new HashMap<>();\n        Map<String, Integer> map2 = new HashMap<>();\n        \n        for (int i = 0; i < s.length(); i++) {\n            char c = s.charAt(i);\n            map.put(c, map.getOrDefault(c, 0) + 1);\n            while (map.size() > maxLetters || i - left + 1 > minSize) { // < maxLetters unique chars\n                char leftChar = s.charAt(left);\n                map.put(leftChar, map.get(leftChar) - 1);\n                if (map.get(leftChar) == 0) {\n                    map.remove(leftChar);\n                }\n                left++;\n            }\n            \n            if (i - left + 1 == minSize) {\n                String sub = s.substring(left, i + 1);\n                map2.put(sub, map2.getOrDefault(sub, 0) + 1);\n                res = Math.max(res, map2.get(sub));\n            }\n        }\n     \n        return res;\n    }\n```
[]