[Java] Sliding Window O(n). 80.08% faster than all Java submissions
Thanks @rorua for the heads up on not needing maxSize. \nRuntime: 49 ms, faster than 80.08% of Java online submissions for Maximum\nMemory Usage: 44.3 MB, less 
Thanks @rorua for the heads up on not needing maxSize. \nRuntime: 49 ms, faster than 80.08% of Java online submissions for Maximum\nMemory Usage: 44.3 MB, less than 94.70% of Java online\n```\npublic int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        Map<String, Integer> substrFreqMap = new HashMap<>();\n        Map<Character, Integer> charFreqMap = new HashMap<>();\n        int maxCount = 0;\n        for (int windowStart = 0, windowEnd = 0; windowEnd < s.length(); windowEnd++) {\n            char endChar = s.charAt(windowEnd);\n            charFreqMap.put(endChar, charFreqMap.getOrDefault(endChar, 0) + 1);\n            while (charFreqMap.size() > maxLetters || (windowEnd - windowStart + 1) > minSize) {\n                char startChar = s.charAt(windowStart++);\n                charFreqMap.put(startChar, charFreqMap.get(startChar) - 1);\n                if (charFreqMap.get(startChar) == 0) {\n                    charFreqMap.remove(startChar);\n                }\n            }\n            if ((windowEnd - windowStart + 1) == minSize) {\n                String substr = s.substring(windowStart, windowEnd + 1);\n                int count = substrFreqMap.getOrDefault(substr, 0) + 1;\n                substrFreqMap.put(substr, count);\n                maxCount = Math.max(maxCount, count);\n            }\n        }\n        return maxCount;\n    }\n```\n\nIf you didn\'t know that maxSize wasn\'t needed then this is how you\'d solve it using maxSize:\nRuntime: 73 ms, faster than 58.90% of Java online submissions\nMemory Usage: 50.5 MB, less than 83.69% of Java online submissions\n```\npublic int maxFreq(String s, int maxLetters, int minSize, int maxSize) {\n        Map<String, Integer> substrFreqMap = new HashMap<>();\n        Map<Character, Integer> charFreqMap = new HashMap<>();\n        int maxCount = 0;\n        for (int windowStart = 0, windowEnd = 0; windowEnd < s.length(); windowEnd++) {\n            char endChar = s.charAt(windowEnd);\n            charFreqMap.put(endChar, charFreqMap.getOrDefault(endChar, 0) + 1);\n            while (charFreqMap.size() > maxLetters || (windowEnd - windowStart + 1) > maxSize) {\n                char startChar = s.charAt(windowStart);\n                charFreqMap.put(startChar, charFreqMap.get(startChar) - 1);\n                if (charFreqMap.get(startChar) == 0) {\n                    charFreqMap.remove(startChar);\n                }\n                windowStart++;\n            }\n            while ((windowEnd - windowStart + 1) >= minSize) {\n                String substr = s.substring(windowStart, windowEnd + 1);\n                int count = substrFreqMap.getOrDefault(substr, 0) + 1;\n                substrFreqMap.put(substr, count);\n                maxCount = Math.max(maxCount, count);\n                if ((windowEnd - windowStart + 1) == minSize) {\n                    break;\n                }\n                char startChar = s.charAt(windowStart);\n                charFreqMap.put(startChar, charFreqMap.get(startChar) - 1);\n                if (charFreqMap.get(startChar) == 0) {\n                    charFreqMap.remove(startChar);\n                }\n                windowStart++;\n            }\n        }\n        return maxCount;\n    }\n```
[]