@@ -0,0 +1,2518 @@
+package com.fishercoder.solutions;%0A%0Aimport java.util.HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set;%0A%0A/**%0A * 1297. Maximum Number of Occurrences of a Substring%0A *%0A * Given a string s, return the maximum number of ocurrences of any substring under the following rules:%0A *%0A * The number of unique characters in the substring must be less than or equal to maxLetters.%0A * The substring size must be between minSize and maxSize inclusive.%0A *%0A * Example 1:%0A * Input: s = %22aababcaab%22, maxLetters = 2, minSize = 3, maxSize = 4%0A * Output: 2%0A * Explanation: Substring %22aab%22 has 2 ocurrences in the original string.%0A * It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).%0A *%0A * Example 2:%0A * Input: s = %22aaaa%22, maxLetters = 1, minSize = 3, maxSize = 3%0A * Output: 2%0A * Explanation: Substring %22aaa%22 occur 2 times in the string. It can overlap.%0A *%0A * Example 3:%0A * Input: s = %22aabcabcab%22, maxLetters = 2, minSize = 2, maxSize = 3%0A * Output: 3%0A *%0A * Example 4:%0A * Input: s = %22abcde%22, maxLetters = 2, minSize = 3, maxSize = 3%0A * Output: 0%0A *%0A * Constraints:%0A * 1 %3C= s.length %3C= 10%5E5%0A * 1 %3C= maxLetters %3C= 26%0A * 1 %3C= minSize %3C= maxSize %3C= min(26, s.length)%0A * s only contains lowercase English letters.%0A * */%0Apublic class _1297 %7B%0A    public static class Solution1 %7B%0A        public int maxFreq(String s, int maxLetters, int minSize, int maxSize) %7B%0A            int maxFreq = 0;%0A            for (int size = minSize; size %3C= maxSize; size++) %7B%0A                maxFreq = Math.max(maxFreq, getMaxFreqWithThisSize(s, maxLetters, size));%0A            %7D%0A            return maxFreq;%0A        %7D%0A%0A        private int getMaxFreqWithThisSize(String str, int maxLetters, int size) %7B%0A            Map%3CString, Integer%3E map = new HashMap%3C%3E();%0A            for (int i = 0; i %3C= str.length() - size; i++) %7B%0A                String substring = str.substring(i, i + size);%0A                Set%3CCharacter%3E set = new HashSet%3C%3E();%0A                for (int j = 0; j %3C substring.length(); j++) %7B%0A                    set.add(substring.charAt(j));%0A                    if (set.size() %3E maxLetters) %7B%0A                        break;%0A                    %7D%0A                %7D%0A                if (set.size() %3C= maxLetters) %7B%0A                    map.put(substring, map.getOrDefault(substring, 0) + 1);%0A                %7D%0A            %7D%0A            int max = 0;%0A            for (String key : map.keySet()) %7B%0A                max = Math.max(max, map.get(key));%0A            %7D%0A            return max;%0A        %7D%0A    %7D%0A%7D%0A

add 1297