description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: d = dict() n = len(s) for i in range(n): j = i st = set() l = 0 while j < min(n, i + maxSize) and l <= maxLetters: if s[j] not in st: l += 1 st.add(s[j]) x = s[i : j + 1] ln = j - i + 1 if ln >= minSize and ln <= maxSize and l <= maxLetters: if x in d: d[x] += 1 else: d[x] = 1 j += 1 if d == dict(): return 0 return max(list(d.values()))
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: max_occ = 0 D = {} for i in range(len(s)): for j in range(i + minSize, i + maxSize + 1): if j <= len(s): s_s = s[i:j] else: continue if len(set(s_s)) <= maxLetters: if s_s in D.keys(): D[s_s] += 1 else: D[s_s] = 1 max_occ = max(D[s_s], max_occ) return max_occ
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: count = defaultdict(int) for size in range(minSize, maxSize + 1): for i in range(0, len(s) - size + 1): st = s[i : size + i] if len(set(st)) <= maxLetters: count[st] += 1 if len(count) == 0: return 0 return max(count.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: maxOccurrences = 0 substrings = dict() for i in range(minSize, maxSize + 1): for j in range(len(s)): if i + j <= len(s): current = s[j : j + i] if len(set(current)) <= maxLetters: if current in substrings: substrings[current] += 1 else: substrings[current] = 1 if substrings[current] > maxOccurrences: maxOccurrences = substrings[current] return maxOccurrences
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s, maxLetters, minSize, maxSize): if minSize > len(s): return 0 left = 0 right = minSize - 1 words = {} while left < len(s) - minSize + 1: word = s[left : right + 1] while ( right < len(s) and right - left < maxSize and len(set(word)) <= maxLetters ): if word not in words: words[word] = 0 words[word] += 1 right += 1 if right < len(s): word += s[right] left += 1 right = left + minSize - 1 maxOccurences = 0 for word in words: maxOccurences = max(maxOccurences, words[word]) return maxOccurences
CLASS_DEF FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT WHILE VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: res = 0 count = Counter() for j in range(len(s) - minSize + 1): if len(set(s[j : j + minSize])) > maxLetters: continue count[s[j : j + minSize]] += 1 res = max(res, count[s[j : j + minSize]]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: freq = collections.defaultdict(int) max_freq = 0 for win in range(minSize, maxSize + 1): for i in range(len(s) - win + 1): sub_seq = s[i : i + win] if len(set(sub_seq)) <= maxLetters: freq[sub_seq] += 1 max_freq = max(max_freq, max(freq.values()) if freq else 0) return max_freq
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if minSize > len(s): return 0 maxCount = 0 seenSubstrs = Counter() for i in range(len(s)): letterSet = set() for j in range(i, i + minSize - 1): if j >= len(s): break letterSet.add(s[j]) if len(letterSet) > maxLetters: break if len(letterSet) > maxLetters: continue for j in range(i + minSize - 1, i + maxSize + 1): if j >= len(s): break letterSet.add(s[j]) if len(letterSet) > maxLetters: break seenSubstrs[s[i : j + 1]] += 1 maxCount = max(seenSubstrs[s[i : j + 1]], maxCount) return maxCount
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if maxLetters == 0: return 0 sw = collections.defaultdict(int) substrings = collections.defaultdict(int) l = 0 res = 0 for r, ch in enumerate(s): sw[ch] += 1 while l <= r and len(sw) > maxLetters: chL = s[l] sw[chL] -= 1 if sw[chL] == 0: del sw[chL] l += 1 for j in range(r + 1 - maxSize, r + 1 - minSize + 1): if j < l: continue substrings[s[j : r + 1]] += 1 res = max(res, substrings[s[j : r + 1]]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: dic = {} for i in range(len(s) - minSize + 1): s1 = s[i : i + minSize] unique = {} for c in s1: if c not in unique: unique[c] = 1 if len(unique) <= maxLetters: if s1 in dic: dic[s1] += 1 else: dic[s1] = 1 if i != len(s) - minSize and minSize != maxSize: s2 = s[i : i + maxSize] if s2[-1] not in unique: unique[s2[-1]] = 1 if len(unique) <= maxLetters: if s2 in dic: dic[s2] += 1 else: dic[s2] = 1 max_occr = 0 for key in dic: if dic[key] > max_occr: max_occr = dic[key] return max_occr
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER VAR ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if len(s) < minSize: return 0 res = 0 def is_good(ss): return len(set(ss)) <= maxLetters for sz in range(minSize, maxSize + 1): cnt = collections.defaultdict(int) for i in range(len(s) - sz + 1): if is_good(s[i : i + sz]): cnt[s[i : i + sz]] += 1 res = max(res, cnt[s[i : i + sz]]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: hashmap = {} occ = {} for i in range(len(s)): hashmap[s[i]] = hashmap.get(s[i], 0) + 1 if i >= minSize: hashmap[s[i - minSize]] -= 1 if hashmap[s[i - minSize]] == 0: del hashmap[s[i - minSize]] if i >= minSize - 1: if len(hashmap) <= maxLetters: substring = s[i - minSize + 1 : i + 1] occ[substring] = occ.get(substring, 0) + 1 if len(occ) == 0: return 0 return max(occ.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: l = 0 r = 0 strMap = collections.defaultdict(int) curr = "" currMap = collections.defaultdict(int) while r < len(s): char = s[r] currMap[char] += 1 curr += char while len(currMap) > maxLetters or len(curr) > minSize: curr = curr[1:] currMap[s[l]] -= 1 if currMap[s[l]] == 0: del currMap[s[l]] l += 1 if len(curr) == minSize: strMap[curr] += 1 r += 1 return max(strMap.values()) if strMap else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR VAR WHILE FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: newDict = {} for j in range(len(s) - minSize + 1): word = s[j : j + minSize] if word in newDict: newDict[word] += 1 elif len(collections.Counter(word)) <= maxLetters: newDict[word] = 1 return max(newDict.values()) if len(newDict) != 0 else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: ret = defaultdict(int) for i in range(len(s)): temp = "" char = set() for j in range(i, len(s)): temp = temp + s[j] char.add(s[j]) if len(char) <= maxLetters and minSize <= len(temp) <= maxSize: ret[temp] += 1 elif len(char) > maxLetters or len(temp) > maxSize: break if len(ret) == 0: return 0 return max(ret.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, m: int, n: int, ss: int) -> int: def getSubStrings(maxLetters: int, minSize: int, maxSize: int): for i in range(len(s)): for j in range(i + minSize, len(s) + 1): if j - i > maxSize: break sub = s[i:j] if len(set(sub)) <= maxLetters: yield sub counter = collections.defaultdict(int) ret = 0 for substring in getSubStrings(m, n, ss): counter[substring] += 1 ret = max(ret, counter[substring]) return ret
CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) dic = collections.defaultdict(int) res = 0 for i in range(n): for j in range(i + minSize - 1, min(i + maxSize, n)): temp = s[i : j + 1] if len(set(temp)) <= maxLetters: dic[temp] += 1 res = max(res, dic[temp]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: dict = {} for i in range(len(s)): for j in range(i + minSize, i + maxSize + 1): if j <= len(s): substr = s[i:j] if len(set(substr)) <= maxLetters: if substr in dict: dict[substr] += 1 else: dict[substr] = 1 max_count = 0 for k, v in list(dict.items()): max_count = max(max_count, v) return max_count
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: res = collections.Counter() b = 0 cc = collections.Counter() for e in range(len(s)): cc[s[e]] += 1 while len(cc) > maxLetters or e - b + 1 > maxSize: cc[s[b]] -= 1 if cc[s[b]] == 0: cc.pop(s[b]) b += 1 i = b while e - i + 1 >= minSize: res[s[i : e + 1]] += 1 i += 1 return res.most_common(1)[0][1] if res else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: seen = Counter() cnt = Counter() j = 0 for i, ss in enumerate(s): cnt[ss] += 1 while len(cnt) > maxLetters and j <= i: cnt[s[j]] -= 1 if not cnt[s[j]]: del cnt[s[j]] j += 1 k = j while i - k + 1 >= minSize: if i - k + 1 <= maxSize: seen[s[k : i + 1]] += 1 k += 1 return max(seen.values()) if seen else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: sol = {} for i in range(len(s) - minSize + 1): count = set() length = 0 for j in range(minSize - 1): length += 1 c = s[i + j] if c not in count: count.add(c) while length < maxSize and i + length < len(s): c = s[i + length] if c not in count: count.add(c) if len(count) <= maxLetters: substring = s[i : i + length + 1] if substring in sol: sol[substring] += 1 else: sol[substring] = 1 length += 1 maximum = 0 for substring in sol: if sol[substring] > maximum: maximum = sol[substring] return maximum
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: onetime = False if minSize == maxSize: onetime = True valid_candidates = {} maxoccurrences = 0 def check_candidates(test): nonlocal maxoccurrences if len(set(test)) <= maxLetters: valid_candidates[test] = valid_candidates.get(test, 0) + 1 maxoccurrences = max(maxoccurrences, valid_candidates[test]) for i in range(len(s)): for j in range(minSize, maxSize + 1): if i + j <= len(s): check_candidates(s[i : i + j]) return maxoccurrences
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) cnt = defaultdict(int) for i in range(n): now = "" se = set() for j in range(maxSize): if i + j >= n: break now += s[i + j] se.add(s[i + j]) if len(se) <= maxLetters and len(now) >= minSize: cnt[now] += 1 ans = 0 for v in cnt.values(): ans = max(ans, v) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: count = 0 ht = collections.Counter() for i in range(len(s)): for j in range(i + 1, len(s) + 1): substring = s[i:j] length = len(substring) if ( length >= minSize and length <= maxSize and len(set(substring)) <= maxLetters ): ht[substring] += 1 elif length > maxSize: break return max(v for k, v in ht.items()) if ht else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s, maxLetters, minSize, maxSize): result = 0 subStringFreq = collections.defaultdict(int) window = collections.defaultdict(int) low = 0 high = 0 while high < len(s): window[s[high]] += 1 if high - low + 1 == minSize: if len(window) <= maxLetters: subStringFreq[s[low : high + 1]] += 1 result = max(result, subStringFreq[s[low : high + 1]]) window[s[low]] -= 1 if window[s[low]] == 0: del window[s[low]] low += 1 high += 1 return result
CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: d = defaultdict(int) s = list(s) n = len(s) for i in range(n - minSize + 1): for j in range(i + minSize, min(i + maxSize + 1, n + 1)): if len(set(s[i:j])) <= maxLetters: d[tuple(s[i:j])] += 1 else: break if not d: return 0 return max(d.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: r = 0 seen = Counter() for i in range(minSize, maxSize + 1): for j in range(i, len(s) + 1): t = s[j - i : j] if len(set(t)) <= maxLetters: seen[t] += 1 if seen[t] > r: r = seen[t] return r
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: store = collections.defaultdict(int) for i in range(0, len(s) - minSize + 1): for j in range(0, maxSize - minSize + 1): if i + j + minSize > len(s): break subS = s[i : i + minSize + j] checkSize = set(subS) if len(checkSize) <= maxLetters: store[subS] += 1 maxNum = 0 for key, val in store.items(): if val > maxNum: maxNum = val return maxNum
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: freq = {} for i in range(0, len(s) - minSize + 1): sub = s[i : i + minSize] chars = set() for c in sub: chars.add(c) if len(chars) <= maxLetters: if sub not in freq: freq[sub] = 0 freq[sub] += 1 best = 0 for sub in freq: if freq[sub] > best: best = freq[sub] return best
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) s0 = s[:minSize] counter = collections.Counter(s0) substr = collections.Counter() if len(counter) <= maxLetters: substr[s0] += 1 for i in range(minSize, n): l = i - minSize counter[s[i - minSize]] -= 1 counter[s[i]] += 1 if counter[s[i - minSize]] == 0: counter.pop(s[i - minSize]) if len(counter) <= maxLetters: substr[s[i - minSize + 1 : i + 1]] += 1 return max(substr.values(), default=0)
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: all_substrings = {} max_letters = maxLetters min_size = minSize max_size = maxSize _s = s ll = len(_s) for i in range(min_size, max_size + 1): for j in range(ll - i + 1): ss = _s[j : j + i] if max_letters >= min_size or len(set(ss)) <= max_letters: if ss not in all_substrings: all_substrings[ss] = 1 else: all_substrings[ss] += 1 return max(all_substrings.values()) if len(all_substrings) > 0 else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: substrings = defaultdict(int) for gap in range(minSize, maxSize + 1): for start in range(len(s) - gap + 1): end = start + gap substrings[s[start:end]] += 1 max_ = 0 for substring, times in substrings.items(): if times > max_ and len(set(substring)) <= maxLetters: max_ = times return max_
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: window_start = 0 window_letters = Counter() substring_counts = Counter() for window_end in range(len(s)): window_letters[s[window_end]] += 1 substring_len = window_end - window_start + 1 while substring_len > maxSize or len(window_letters) > maxLetters: start_char = s[window_start] window_letters[start_char] -= 1 if window_letters[start_char] == 0: del window_letters[start_char] window_start += 1 substring_len = window_end - window_start + 1 while substring_len >= minSize: assert substring_len <= maxSize substring = s[window_start : window_end + 1] substring_counts[substring] += 1 start_char = s[window_start] window_letters[start_char] -= 1 if window_letters[start_char] == 0: del window_letters[start_char] window_start += 1 substring_len = window_end - window_start + 1 print(substring_counts) if not substring_counts: return 0 return max(substring_counts.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: dict = {} left, right = 0, minSize while left < len(s): while right - left <= maxSize and right <= len(s): sub = s[left:right] if self.isSize(sub, minSize, maxSize) and self.isUniqueAmount( sub, maxLetters ): self.addToDict(sub, dict) right += 1 left += 1 right = left + minSize retValue = 0 for k, v in list(dict.items()): retValue = max(retValue, v) return retValue def addToDict(self, sub: str, dict: {}) -> None: if sub not in dict: dict[sub] = 0 dict[sub] += 1 def isSize(self, s: str, minSize: int, maxSize: int) -> bool: length = len(s) return minSize <= length and maxSize >= length def isUniqueAmount(self, s: str, maxLetters: int) -> bool: return len(set(s)) <= maxLetters
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF VAR DICT IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER NONE FUNC_DEF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR VAR VAR VAR FUNC_DEF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: start = 0 end = 0 sub = {} result = {} self.max_size = 0 def add_sub(pos): if s[pos] in sub: sub[s[pos]] += 1 else: sub[s[pos]] = 1 def rem_sub(pos): if s[pos] in sub: if sub[s[pos]] == 1: del sub[s[pos]] else: sub[s[pos]] -= 1 def add_res(string): if string in result: result[string] += 1 else: result[string] = 1 self.max_size = max(self.max_size, result[string]) for size in range(minSize, maxSize + 1): while start <= len(s) - size: if end - start + 1 < size: add_sub(end) end += 1 else: add_sub(end) if len(sub) <= maxLetters: add_res(s[start : end + 1]) rem_sub(start) start += 1 end += 1 start = 0 end = 0 sub = {} return self.max_size
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR VAR IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: left = 0 result = 0 count = collections.defaultdict(int) occurances = collections.defaultdict(int) for right, char in enumerate(s): count[char] += 1 while right - left + 1 > minSize: count[s[left]] -= 1 if count[s[left]] == 0: del count[s[left]] left += 1 if right - left + 1 == minSize and len(count) <= maxLetters: occurances[s[left : right + 1]] += 1 result = max(result, occurances[s[left : right + 1]]) return result
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: occurence = {} for i in range(len(s)): for j in range(minSize, maxSize + 1): if i + j > len(s): break if len(set(s[i : i + j])) <= maxLetters: if s[i : i + j] not in occurence: occurence[s[i : i + j]] = 0 occurence[s[i : i + j]] += 1 if len(occurence) == 0: return 0 return max(occurence.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: i = 0 j = 0 map1 = {} res = {} while j < len(s): map1[s[j]] = map1.get(s[j], 0) + 1 if len(map1.keys()) > maxLetters: map1[s[i]] = map1[s[i]] - 1 if map1[s[i]] == 0: del map1[s[i]] i += 1 while ( len(map1.keys()) <= maxLetters and j - i + 1 <= maxSize and j - i + 1 >= minSize ): res[s[i : j + 1]] = res.get(s[i : j + 1], 0) + 1 map1[s[i]] = map1[s[i]] - 1 if map1[s[i]] == 0: del map1[s[i]] i = i + 1 j = j + 1 if len(res) == 0: return 0 else: maximum = max(res, key=res.get) return res[maximum]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: subset_d = {} for i in range(minSize, maxSize + 1): for j in range(0, len(s) - i + 1): substr = s[j : j + i] subset_d[substr] = subset_d.get(substr, 0) + 1 max_occur = 0 for substr, val in list(subset_d.items()): temp_s = set(list(substr)) if val > max_occur and len(temp_s) <= maxLetters: max_occur = val return max_occur
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: wordCounter = collections.defaultdict() for i in range(maxSize - minSize + 1): charCounter = collections.Counter(s[: minSize + i]) if len(charCounter) <= maxLetters: wordCounter[s[: minSize + i]] = 1 for j in range(minSize + i, len(s)): charCounter[s[j - minSize - i]] -= 1 if charCounter[s[j - minSize - i]] <= 0: del charCounter[s[j - minSize - i]] charCounter[s[j]] += 1 if len(charCounter) <= maxLetters: if s[j - minSize - i + 1 : j + 1] in wordCounter: wordCounter[s[j - minSize - i + 1 : j + 1]] += 1 else: wordCounter[s[j - minSize - i + 1 : j + 1]] = 1 maxTimes = 0 for subString in wordCounter: maxTimes = max(wordCounter[subString], maxTimes) return maxTimes
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: strcount = Counter() unique = set(s[:minSize]) front = 0 back = minSize while back < len(s): if len(unique) <= maxLetters: strcount[s[front:back]] = strcount.get(s[front:back], 0) + 1 front += 1 back += 1 unique = set(s[front:back]) if len(unique) <= maxLetters: strcount[s[front:back]] = strcount.get(s[front:back], 0) + 1 return max(list(strcount.values()) or [0])
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if not s: return 0 n = len(s) substring_count = defaultdict(int) memo_char = defaultdict(int) reader = 0 writer = 0 while reader < len(s): ch = s[reader] memo_char[ch] += 1 window_len = reader - writer + 1 while len(memo_char) > maxLetters or window_len > minSize: wch = s[writer] memo_char[wch] -= 1 if memo_char[wch] == 0: del memo_char[wch] writer += 1 window_len = reader - writer + 1 if window_len >= minSize and window_len <= maxSize: substring_count[tuple(s[writer : reader + 1])] += 1 reader += 1 if not substring_count: return 0 return max(substring_count.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) res_dict = collections.defaultdict(int) for lidx in range(n - minSize + 1): lval = lidx + minSize rval = min(n, lidx + maxSize + 1) for ridx in range(lval, 1 + rval): counts = set(s[lidx:ridx]) if len(counts) <= maxLetters: res_dict[s[lidx:ridx]] += 1 else: break return max(res_dict.values()) if res_dict else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: lenS = len(s) uniqSubStrDict = {} count = 0 Max = 0 for i in range(minSize, maxSize + 1): for j in range(lenS - i + 1): tstSubStr = s[j : j + i] uniqChars = {} for k in tstSubStr: uniqChars[k] = 1 if len(uniqChars) > maxLetters: continue uniqSubStrDict[tstSubStr] = uniqSubStrDict.get(tstSubStr, 0) + 1 if uniqSubStrDict[tstSubStr] > Max: Max = uniqSubStrDict[tstSubStr] count = Max return count
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if len(s) < minSize: return 0 if minSize > maxSize: return 0 res = 0 d = {} for i in range(len(s) - minSize + 1): temp = s[i : i + minSize] if len(set(temp)) <= maxLetters: d[temp] = d.get(temp, 0) + 1 res = max(res, d[temp]) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: word_dic = {} str_dic = {} r_end = 0 ans = 0 def update_ans(length): if length >= minSize: return min(length, maxSize) - minSize + 1 return 0 for i in range(len(s)): while r_end < len(s): ch = s[r_end] if ch in list(word_dic.keys()): word_dic[ch] += 1 elif len(list(word_dic.keys())) < maxLetters: word_dic[ch] = 1 else: break r_end += 1 for j in range(minSize, min(maxSize, r_end - i) + 1): subs = s[i : i + j] if subs not in str_dic: str_dic[subs] = 1 else: str_dic[subs] += 1 word_dic[s[i]] -= 1 if word_dic[s[i]] == 0: del word_dic[s[i]] if not bool(str_dic): return 0 else: return max(str_dic.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR VAR RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: freq = collections.defaultdict(int) for i in range(len(s) - minSize + 1): freq[s[i : i + minSize]] += 1 mx = 0 for key in freq: if len(set(key)) <= maxLetters and mx < freq[key]: mx = freq[key] return mx
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: dic = {} for outer in range(0, len(s)): if minSize + outer > len(s): break substring = s[outer : minSize + outer] while len(substring) <= maxSize and len(set(substring)) <= maxLetters: if dic.get(substring): dic[substring] += 1 else: dic[substring] = 1 newIndex = outer + len(substring) + 1 if not newIndex > len(s): substring = s[outer:newIndex] else: break if dic: maxKey = max(dic, key=lambda key: dic[key]) return dic[maxKey] else: return 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR WHILE FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR RETURN NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: count = 0 diff = maxSize - minSize hashM = {} maxC = float("-inf") for r in range(len(s) - minSize + 1): for i in range(diff + 1): if r + minSize + i <= len(s): if len(set(s[r : r + minSize + i])) <= maxLetters: hashM[s[r : r + minSize + i]] = ( hashM.get(s[r : r + minSize + i], 0) + 1 ) maxC = max(maxC, hashM[s[r : r + minSize + i]]) return maxC if maxC != float("-inf") else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_CALL VAR STRING VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def findSubstring(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> str: len_s = len(s) substrings = {} for i in range(len_s): for j in range(i + minSize, i + maxSize + 1): if j > len_s: break substring = s[i:j] if len(set(substring)) <= maxLetters: if substring not in substrings: substrings[substring] = 0 substrings[substring] += 1 return substrings def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: len_s = len(s) if len_s < minSize: return 0 substrings = self.findSubstring(s, maxLetters, minSize, maxSize) if not substrings: return 0 return max(substrings.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER RETURN VAR VAR FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: all_substrings = {} for i in range(minSize, maxSize + 1): for j in range(len(s) - i + 1): ss = s[j : j + i] if len(set(ss)) <= maxLetters: if ss not in all_substrings: all_substrings[ss] = 0 all_substrings[ss] += 1 if len(all_substrings) > 0: return max(all_substrings.values()) else: return 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR RETURN NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: start = 0 end = minSize counts = {} res = 0 while start <= len(s) - minSize: item = s[start:end] counts[item] = counts.get(item, 0) + 1 start += 1 end += 1 for i in counts: if self.countUnique(i) <= maxLetters: res = max(res, counts[i]) return res def countUnique(self, s): return len(set(s))
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: i = 0 lst = [] while i < len(s): for j in range(minSize, maxSize + 1): subs = s[i : i + j] sc = set(subs) if len(sc) > maxLetters: continue if len(subs) >= minSize and len(subs) <= maxSize and i + j <= len(s): lst.append(subs) i += 1 c = collections.Counter(lst) maxs = 0 for subs2 in c: maxs = max(c[subs2], maxs) return maxs
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: tracker = collections.defaultdict(int) window_tracker = collections.defaultdict(int) curr_sum = 0 i = 0 j = 0 while j < len(s): curr = s[j] window_tracker[curr] += 1 curr_sum += 1 while i < j and curr_sum > minSize: curr_i = s[i] curr_sum -= 1 window_tracker[curr_i] -= 1 if window_tracker[curr_i] == 0: del window_tracker[curr_i] i += 1 temp = collections.defaultdict(int) toAdd = s[i : j + 1] for char in toAdd: temp[char] += 1 if minSize <= curr_sum <= maxSize and len(temp.keys()) <= maxLetters: tracker[s[i : j + 1]] += 1 j += 1 print(tracker) if len(tracker.values()) == 0: return 0 return max(tracker.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: freq = Counter() for leftInd, char in enumerate(s): seen = set([]) for rightInd in range(leftInd, leftInd + maxSize): if rightInd > len(s) - 1: break seen.add(s[rightInd]) if len(seen) > maxLetters: break if maxSize >= rightInd - leftInd + 1 >= minSize: freq[s[leftInd : rightInd + 1]] += 1 ret = 0 for key, val in freq.items(): ret = max(ret, val) return ret
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: l = len(s) ans = 0 for i in range(minSize, maxSize + 1): mp = collections.defaultdict(int) for j in range(l - i + 1): cc = collections.defaultdict(int) sub = s[j : j + i] if len(set(sub)) <= maxLetters: mp[sub] += 1 if len(mp.keys()) > 0: ans = max(max(mp.values()), ans) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: freq = defaultdict(lambda: 0) m = "" n = len(s) for i in range(n - minSize + 1): end = i + minSize unique = set(s[i:end]) while end <= n: unique.add(s[end - 1]) if len(unique) > maxLetters: break cur = s[i:end] freq[cur] += 1 if freq[cur] > freq[m]: m = cur end += 1 return freq[m]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: res = collections.defaultdict(int) for k in range(minSize, minSize + 1): counter = collections.Counter(s[:k]) for i in range(k, len(s)): if len(counter.keys()) <= maxLetters: res[s[i - k : i]] += 1 counter[s[i]] += 1 counter[s[i - k]] -= 1 if counter[s[i - k]] == 0: del counter[s[i - k]] if len(counter.keys()) <= maxLetters: res[s[i - k + 1 :]] += 1 return max(res.values()) if res else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: k = minSize count = collections.Counter(s[i : i + k] for i in range(len(s) - k + 1)) return max([count[w] for w in count if len(set(w)) <= maxLetters] + [0])
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR LIST NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: maxcount = 0 visited = {} for i in range(len(s)): for j in range(minSize, minSize + 1): now = s[i : i + j] if now in visited: continue visited[now] = 1 if i + j > len(s): break nowset = set(now) if len(nowset) > maxLetters: break count = 1 start = i + 1 while start < len(s): pos = s.find(now, start) if pos != -1: start = pos + 1 count += 1 else: break maxcount = max(maxcount, count) return maxcount
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: counterSubstring = collections.defaultdict(int) best = 0 for start in range(len(s)): if start + minSize <= len(s): substring = s[start : start + minSize] counterSubstring[substring] += 1 for substring in counterSubstring: if len(set(substring)) <= maxLetters: best = max(best, counterSubstring[substring]) return best
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: count = defaultdict(int) for size in range(minSize, maxSize + 1): q = deque() for i in range(0, len(s)): q.append(s[i]) if i > size - 1: q.popleft() if i >= size - 1 and len(set(q)) <= maxLetters: count[tuple(q)] += 1 if len(count) == 0: return 0 return max(count.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) if n < minSize: return 0 c = collections.Counter() for start in range(n - minSize + 1): temp = s[start : start + minSize] tc = collections.Counter(temp) if len(tc.keys()) <= maxLetters: c[temp] += 1 else: continue for i in range(start + minSize, min(n, start + maxSize)): tc[s[i]] += 1 temp += s[i] if len(tc.keys()) <= maxLetters: c[temp] += 1 else: continue return max(c.values() or [0])
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = 0 left = 0 right = minSize - 1 d = {} length = len(s) unique_let = {} def popLetter(letter, n): unique_let[letter] -= 1 if unique_let[letter] == 0: n -= 1 return n def addLetter(letter, n): if unique_let.get(letter, 0) == 0: n += 1 unique_let[letter] = unique_let.get(letter, 0) + 1 return n for letter in s[: minSize - 1]: n = addLetter(letter, n) print(n) print(unique_let) while right < length: if left > 0: n = popLetter(s[left - 1], n) n = addLetter(s[right], n) print(n) if n <= maxLetters: d[s[left : right + 1]] = d.get(s[left : right + 1], 0) + 1 right += 1 left += 1 print(d) if not d.values(): return 0 return max(d.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: validStrings = {} for currSize in range(minSize, maxSize + 1): self.getValidString(currSize, s, maxLetters, validStrings) return self.getMaxCount(validStrings) def getValidString(self, currSize, s, maxLetters, validStrings): left = 0 right = 0 currWindow = {} uniqueCounts = 0 for right in range(currSize): uniqueCounts = self.insert(s[right], currWindow, uniqueCounts) self.insertValidString(uniqueCounts, maxLetters, left, right, s, validStrings) while right < len(s) - 1: uniqueCounts = self.insert(s[right + 1], currWindow, uniqueCounts) uniqueCounts = self.remove(s[left], currWindow, uniqueCounts) left += 1 right += 1 self.insertValidString( uniqueCounts, maxLetters, left, right, s, validStrings ) def insert(self, char, currWindow, uniqueCounts): if char not in currWindow: currWindow[char] = 1 uniqueCounts += 1 else: currWindow[char] += 1 return uniqueCounts def remove(self, char, currWindow, uniqueCounts): currWindow[char] -= 1 if currWindow[char] == 0: del currWindow[char] uniqueCounts -= 1 return uniqueCounts def getMaxCount(self, validStrings): maxCount = 0 for string in validStrings: if validStrings[string] > maxCount: maxCount = validStrings[string] return maxCount def insertValidString(self, uniqueCounts, maxLetters, left, right, s, validStrings): if uniqueCounts <= maxLetters: currWord = s[left : right + 1] if currWord not in validStrings: validStrings[currWord] = 1 else: validStrings[currWord] += 1
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: substr = defaultdict(int) n = len(s) unique = set() max_freq = 0 for i in range(n - minSize + 1): current_str = s[i : i + minSize] if len(set(current_str)) <= maxLetters: substr[current_str] += 1 max_freq = max(max_freq, substr[current_str]) return max_freq
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: seen = collections.defaultdict(int) n = len(s) for k in range(minSize, maxSize + 1): counts = collections.Counter(s[:k]) if len(counts) <= maxLetters: seen[s[:k]] += 1 for i in range(n - k): counts[s[i]] -= 1 if counts[s[i]] == 0: del counts[s[i]] counts[s[i + k]] += 1 if len(counts) <= maxLetters: seen[s[i + 1 : i + k + 1]] += 1 return max(seen.values()) if len(seen) > 0 else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: cur_soln = {s[:minSize]: 1} for end in range(minSize, len(s)): for start in range(end - minSize + 1, max(-1, end - maxSize), -1): subs = s[start : end + 1] cur_soln[subs] = cur_soln.get(subs, 0) + 1 cur_best = 0 for s, cnt in list(cur_soln.items()): if cnt > cur_best and len(set(s)) <= maxLetters: cur_best = cnt return cur_best
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: left = 0 right = 0 _dict = defaultdict(int) _dict2 = defaultdict(int) while right < len(s): _dict[s[right]] += 1 while ( len(_dict) > maxLetters or right - left + 1 > maxSize or right - left + 1 > minSize ): _dict[s[left]] -= 1 if _dict[s[left]] == 0: del _dict[s[left]] left += 1 if len(_dict) <= maxLetters and minSize <= right - left + 1 <= maxSize: _dict2[s[left : right + 1]] += 1 right += 1 if len(_dict2) == 0: return 0 return max(_dict2.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: validWords = {} for i in range(0, len(s)): for j in range(i + minSize - 1, min(i + maxSize, len(s))): ss = s[i : j + 1] if len(set(ss)) <= maxLetters: if ss in validWords: validWords[ss] += 1 else: validWords[ss] = 1 if validWords: all_values = validWords.values() return max(all_values) else: return 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR RETURN NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: occ, n = {}, len(s) for i in range(n): for j in range(i + minSize - 1, min(i + maxSize, n)): sub = s[i : j + 1] if len(set(sub)) <= maxLetters: occ[sub] = occ.get(sub, 0) + 1 return max(list(occ.values()) or [0])
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR DICT FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: count = 0 n = len(s) count = Counter() for i in range(n - minSize + 1): r = i + minSize seen = {c for c in s[i:r]} unique = len(seen) while unique <= maxLetters and r <= n and r - i <= maxSize: if s[r - 1] not in seen: unique += 1 seen.add(s[r - 1]) count[s[i:r]] += 1 r += 1 return max(count.values()) if count else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if len(s) == 0: return 0 rolling_hash = 0 letter_counts = collections.Counter() hash_counts = collections.Counter() unique_letters = set() n = len(s) for i in range(n): ch = s[i] rolling_hash = rolling_hash * 26 + ord(ch) letter_counts[ch] += 1 unique_letters.add(ch) if i + 1 < minSize: continue if len(unique_letters) <= maxLetters: hash_counts[rolling_hash] += 1 remove_letter = s[i - minSize + 1] rolling_hash -= ord(remove_letter) * 26 ** (minSize - 1) letter_counts[remove_letter] -= 1 if letter_counts[remove_letter] == 0: unique_letters.remove(remove_letter) return max(hash_counts.values()) if len(hash_counts) else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: l = 0 r = 0 strMap = collections.defaultdict(int) curr = "" currMap = collections.defaultdict(int) unique = 0 while r < len(s): char = s[r] if currMap[char] == 0: unique += 1 currMap[char] += 1 curr += char while unique > maxLetters or len(curr) > minSize: curr = curr[1:] currMap[s[l]] -= 1 if currMap[s[l]] == 0: unique -= 1 l += 1 print(curr) if len(curr) >= minSize: strMap[curr] += 1 r += 1 return max(list(strMap.values()) or (0, 0))
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR WHILE VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) d = collections.defaultdict(int) for i in range(0, n - minSize + 1): temp = s[i : i + minSize] c = set(temp) if len(c) <= maxLetters: d[temp] += 1 return max(d.values()) if d else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: dict = {} left, right = 0, minSize while left < len(s): while right - left <= maxSize and right <= len(s): sub = s[left:right] if sub in dict: dict[sub] += 1 elif self.isUniqueAmount(sub, maxLetters): dict[sub] = 1 right += 1 left += 1 right = left + minSize retValue = 0 for k, v in list(dict.items()): retValue = max(retValue, v) return retValue def isUniqueAmount(self, s: str, maxLetters: int) -> bool: return len(set(s)) <= maxLetters
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER VAR WHILE VAR FUNC_CALL VAR VAR WHILE BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: maxOcc = 0 strOcc = {} for i in range(minSize, maxSize + 1): charFreq = {} sub = s[:i] uniqueChar = 0 for c in sub: if c not in charFreq: charFreq[c] = 0 uniqueChar += 1 charFreq[c] += 1 if uniqueChar <= maxLetters: if sub not in strOcc: strOcc[sub] = 0 strOcc[sub] += 1 maxOcc = max(maxOcc, strOcc[sub]) for j in range(i, len(s)): outC = sub[0] inC = s[j] charFreq[outC] -= 1 if charFreq[outC] == 0: uniqueChar -= 1 del charFreq[outC] if inC not in charFreq: charFreq[inC] = 0 uniqueChar += 1 charFreq[inC] += 1 sub = sub[1:] + inC if uniqueChar <= maxLetters: if sub not in strOcc: strOcc[sub] = 0 strOcc[sub] += 1 maxOcc = max(maxOcc, strOcc[sub]) return maxOcc
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: c = Counter() i = 0 letterlen = 0 maxSize = maxSize + 1 if maxSize == minSize else maxSize ans = Counter() for j, v in enumerate(s): c[v] += 1 if c[v] == 1: letterlen += 1 while letterlen > maxLetters: x = s[i] c[x] -= 1 if c[x] == 0: letterlen -= 1 i += 1 for l in range(minSize, maxSize): beg = j - l + 1 if beg >= i: ans[s[beg : j + 1]] += 1 return max(ans.values()) if ans else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, a: int, b: int) -> int: cnt = collections.defaultdict(int) for i in range(len(s) - a + 1): cnt[s[i : i + a]] += 1 for a, v in sorted(cnt.items(), key=lambda x: x[1], reverse=True): if len(set(a)) <= maxLetters: return v return 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR RETURN NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: my_dict = {} for i in range(len(s) - minSize + 1): if len(set(s[i : i + minSize])) <= maxLetters: if s[i : i + minSize] in my_dict: my_dict[s[i : i + minSize]] += 1 else: my_dict[s[i : i + minSize]] = 1 k = minSize + 1 if minSize != maxSize: while maxSize >= k: for i in range(len(s) - k + 1): if len(set(s[i : i + k])) <= maxLetters: if s[i : i + k] in my_dict: my_dict[s[i : i + k]] += 1 else: my_dict[s[i : i + k]] = 1 k += 1 return max(my_dict.values()) if my_dict else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: max_freq = 0 for l in range(minSize, maxSize + 1): hmap = {} for i in range(len(s) - l + 1): if len(set(s[i : i + l])) <= maxLetters: if s[i : i + l] in list(hmap.keys()): hmap[s[i : i + l]] += 1 else: hmap[s[i : i + l]] = 1 if list(hmap.keys()): max_freq = max( max_freq, max(list(hmap.items()), key=lambda kv: kv[1])[1] ) return max_freq
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: seen = defaultdict(lambda: 0) m = defaultdict(lambda: 0) left = 0 for i in range(len(s)): m[s[i]] += 1 while len(m) > maxLetters or i - left + 1 > maxSize: m[s[left]] -= 1 if m[s[left]] == 0: m.pop(s[left]) left += 1 temp = left while i - temp + 1 >= minSize: seen[s[temp : i + 1]] += 1 temp += 1 if not seen: return 0 return max(list(seen.values()))
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: if not s or len(s) < minSize: return 0 gMax = -1 while minSize <= maxSize: start = 0 end = minSize - 1 freqMap = {} lMax = 0 while end < len(s): sub = s[start : end + 1] if sub in freqMap or self.checkUnique(sub, maxLetters): if sub not in freqMap: freqMap[sub] = 1 else: freqMap[sub] += 1 if freqMap[sub] > lMax: lMax = freqMap[sub] start += 1 end += 1 if lMax > gMax: gMax = lMax minSize += 1 return gMax def checkUnique(self, string, maxLetters): sett = set(string) if len(sett) > maxLetters: return False else: return True
CLASS_DEF FUNC_DEF VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) count = collections.Counter( s[i : i + minSize] for i in range(0, n - minSize + 1) ) res = 0 for k, v in count.items(): if len(set(k)) <= maxLetters: res = max(res, v) return res
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: N = len(s) d1 = {} maxval = 0 for i in range(N - minSize + 1): d = {} for j in range(i, i + minSize): if s[j] not in d: d[s[j]] = 1 else: d[s[j]] += 1 if len(d) <= maxLetters: if s[i : i + minSize] not in d1: d1[s[i : i + minSize]] = 1 else: d1[s[i : i + minSize]] += 1 maxval = max(maxval, d1[s[i : i + minSize]]) else: continue for j in range(i + minSize, min(i + maxSize, N)): if s[j] not in d: d[s[j]] = 1 else: d[s[j]] += 1 if len(d) <= maxLetters: if s[i : j + 1] not in list(d1.keys()): d1[s[i : j + 1]] = 1 else: d1[s[i : j + 1]] += 1 maxval = max(maxval, d1[s[i : j + 1]]) else: break return maxval
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: subs = {} i = j = 0 chars = {} while i < len(s): if j < len(s) and (s[j] in chars or len(chars) < maxLetters): if s[j] not in chars: chars[s[j]] = 0 chars[s[j]] += 1 j += 1 else: for k in range(i + minSize, min(i + maxSize, j) + 1): sub = s[i:k] if sub not in subs: subs[sub] = 0 subs[sub] += 1 chars[s[i]] -= 1 if chars[s[i]] == 0: del chars[s[i]] i += 1 return max(list(subs.values()) or [0])
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR VAR NUMBER ASSIGN VAR DICT WHILE VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR LIST NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: def valid(sub): seen = set() for c in sub: seen.add(c) return len(seen) counts = dict() start = 0 while start < len(s): end = start + minSize while end <= len(s) and end <= start + maxSize: sub = s[start:end] if sub in counts: counts[sub] += 1 else: num_letters = valid(sub) if num_letters <= maxLetters: counts[sub] = 1 else: break end += 1 start += 1 l = list(counts.values()) if len(l) == 0: return 0 return max(l)
CLASS_DEF FUNC_DEF VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: substrings = defaultdict(int) char_counts = Counter(s[0 : minSize - 1]) start = 0 while start <= len(s) - minSize: end = start + minSize - 1 end_char = s[end] char_counts[end_char] += 1 unique_chars = len(char_counts) if unique_chars <= maxLetters: substrings[s[start : end + 1]] += 1 start_char = s[start] if char_counts[start_char] == 1: del char_counts[start_char] else: char_counts[start_char] -= 1 start += 1 maxSubstrings = 0 for substring in substrings: if substrings[substring] > maxSubstrings: maxSubstrings = substrings[substring] return maxSubstrings
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: cnt = Counter() for sz in range(minSize, min(maxSize, len(s)) + 1): cur = Counter(s[:sz]) if len(cur) <= maxLetters: cnt[s[:sz]] += 1 for i in range(1, len(s) - sz + 1): cur[s[i + sz - 1]] += 1 cur[s[i - 1]] -= 1 if cur[s[i - 1]] == 0: cur.pop(s[i - 1]) if len(cur) <= maxLetters: cnt[s[i : i + sz]] += 1 return max(cnt.values()) if cnt else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: memo_dict = {} for i in range(len(s)): for j in range(i, len(s) + 1): if j - i < minSize: continue if j - i > minSize: break temp = [] temp_str = s[i:j] for char in temp_str: temp.append(char) if len(set(temp)) > maxLetters: continue if temp_str in memo_dict: memo_dict[temp_str] += 1 else: memo_dict[temp_str] = 1 if len(memo_dict) == 0: return 0 res = sorted(memo_dict, key=lambda x: memo_dict[x]) return memo_dict[res[-1]]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: substrings = dict() for i in range(minSize - 1, maxSize): for j in range(i, len(s)): if len(set(s[j - i : j + 1])) <= maxLetters: substrings[s[j - i : j + 1]] = ( substrings.get(s[j - i : j + 1], 0) + 1 ) return max(substrings.values()) if len(substrings) else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: ln_s = len(s) ans = 0 seen = Counter() for i in range(ln_s): set_buff = set(s[i : i + minSize]) for j in range(i + minSize - 1, min(ln_s, i + maxSize)): buff = s[i : j + 1] set_buff.add(s[j]) if len(set_buff) > maxLetters: break seen[buff] += 1 ans = max(ans, seen[buff]) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: d = defaultdict(int) for i in range(len(s) - minSize + 1): letters = set(s[i : i + minSize - 1]) for j in range(minSize, min(maxSize, len(s) - i) + 1): letters.add(s[i + j - 1]) if len(letters) > maxLetters: break d[s[i : i + j]] += 1 return max(d.values()) if d else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER RETURN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: n = len(s) substr = collections.Counter() counter = [collections.Counter(s[:minSize])] if len(counter[-1]) <= maxLetters: substr[s[:minSize]] += 1 for i in range(1, maxSize - minSize + 1): counter.append(collections.Counter(counter[-1])) counter[-1][s[minSize + i - 1]] += 1 if len(counter[-1]) <= maxLetters: substr[s[: minSize + i]] += 1 for i in range(minSize, n): l = i - minSize for j, cnt in enumerate(counter): r = i + j if r >= n: break cnt[s[l]] -= 1 cnt[s[r]] += 1 if cnt[s[l]] == 0: cnt.pop(s[l]) if len(cnt) <= maxLetters: substr[s[l + 1 : r + 1]] += 1 return max(substr.values(), default=0)
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: i = numUnique = 0 N = len(s) count = collections.defaultdict(int) seen = collections.defaultdict(int) ans = 0 for i in range(N): count = collections.defaultdict(int) numUnique = 0 power = 1 hash = 0 for j in range(i, min(i + 26, N)): count[s[j]] += 1 if count[s[j]] == 1: numUnique += 1 add = (ord(s[j]) - ord("a") + 1) * 27**power hash += add power += 1 if numUnique > maxLetters or j - i + 1 > maxSize: break if minSize <= j - i + 1 <= maxSize and numUnique <= maxLetters: seen[hash] += 1 ans = max(ans, seen[hash]) return ans
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER BIN_OP NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: hash, w_hash, res = {}, {}, float("-inf") self.initial_fill(s, minSize, hash) for i in range(0, len(s) - minSize + 1): if len(hash) <= maxLetters: string = s[i : i + minSize] w_hash[string] = 1 if string not in w_hash else w_hash[string] + 1 res = max(res, w_hash[string]) char = s[i] if hash[char] == 1: del hash[char] else: hash[char] -= 1 if i + minSize < len(s): char = s[i + minSize] hash[char] = 1 if char not in hash else hash[char] + 1 return res if res != float("-inf") else 0 def initial_fill(self, s, Min, hash): for i in range(0, Min): char = s[i] hash[char] = 1 if char not in hash else hash[char] + 1
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR VAR VAR DICT DICT FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN VAR FUNC_CALL VAR STRING VAR NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: found = collections.defaultdict(int) for sl in range(minSize, min(len(s), maxSize) + 1): for start_index in range(len(s) - sl + 1): substring = s[start_index : start_index + sl] if len(set(substring)) <= maxLetters: found[substring] += 1 vals = sorted(found.values()) if len(vals) == 0: return 0 return vals[-1]
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, S, maxchars, minsize, maxsize): n = len(S) freq = Counter() chars = Counter() i = 0 for j in range(n): if j - i + 1 > minsize: chars[S[i]] -= 1 if chars[S[i]] == 0: del chars[S[i]] i += 1 chars[S[j]] += 1 if j - i + 1 >= minsize: if len(chars) <= maxchars: freq[S[i : j + 1]] += 1 return max(freq.values(), default=0)
CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR NUMBER
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: counts = {} for current_size in range(minSize, maxSize + 1): window = {} for i in range(current_size - 1): c = s[i] window[c] = window.get(c, 0) + 1 for i in range(current_size - 1, len(s)): start = i - current_size c = s[i] window[c] = window.get(c, 0) + 1 if start >= 0: c = s[start] window[c] -= 1 if window[c] == 0: del window[c] if len(window) <= maxLetters: sub = s[start + 1 : i + 1] counts[sub] = counts.get(sub, 0) + 1 return max(counts.values()) if len(counts) else 0
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR
Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters. The substring size must be between minSize and maxSize inclusive.   Example 1: Input: s = "aababcaab", maxLetters = 2, minSize = 3, maxSize = 4 Output: 2 Explanation: Substring "aab" has 2 ocurrences in the original string. It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize). Example 2: Input: s = "aaaa", maxLetters = 1, minSize = 3, maxSize = 3 Output: 2 Explanation: Substring "aaa" occur 2 times in the string. It can overlap. Example 3: Input: s = "aabcabcab", maxLetters = 2, minSize = 2, maxSize = 3 Output: 3 Example 4: Input: s = "abcde", maxLetters = 2, minSize = 3, maxSize = 3 Output: 0   Constraints: 1 <= s.length <= 10^5 1 <= maxLetters <= 26 1 <= minSize <= maxSize <= min(26, s.length) s only contains lowercase English letters.
class Solution: def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int: counter = dict() n = len(s) for i in range(n - minSize + 1): for j in range(i + minSize - 1, i + maxSize): if j >= n: break if len(set(s[i : j + 1])) <= maxLetters: counter[s[i : j + 1]] = counter.get(s[i : j + 1], 0) + 1 if list(counter.values()) == []: return 0 return max(counter.values())
CLASS_DEF FUNC_DEF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR IF VAR VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR FUNC_CALL VAR LIST RETURN NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR