<p>Given a string <code>s</code>, return the maximum number of occurrences of <strong>any</strong> substring under the following rules:</p>

<ul>
	<li>The number of unique characters in the substring must be less than or equal to <code>maxLetters</code>.</li>
	<li>The substring size must be between <code>minSize</code> and <code>maxSize</code> inclusive.</li>
</ul>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aababcaab&quot;, maxLetters = 2, minSize = 3, maxSize = 4
<strong>Output:</strong> 2
<strong>Explanation:</strong> Substring &quot;aab&quot; has 2 occurrences in the original string.
It satisfies the conditions, 2 unique letters and size 3 (between minSize and maxSize).
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> s = &quot;aaaa&quot;, maxLetters = 1, minSize = 3, maxSize = 3
<strong>Output:</strong> 2
<strong>Explanation:</strong> Substring &quot;aaa&quot; occur 2 times in the string. It can overlap.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= maxLetters &lt;= 26</code></li>
	<li><code>1 &lt;= minSize &lt;= maxSize &lt;= min(26, s.length)</code></li>
	<li><code>s</code> consists of only lowercase English letters.</li>
</ul>

class Solution:
    def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:
        # uniqueletter <= maxLetter
        # minSize <= len(substring) <= maxsize
        # 1 <= s.length <= 10^5
        # 1 <= maxLetters <= 26
        # count the max of the occurrence of the strings fit into these category
        l = r = 0
        n = len(s)
        freq_map = {}

        while l < n:
            while r < n and r - l + 1 <= maxSize:
                if r - l + 1 >= minSize:
                    substring = s[l:r + 1]
                    unique_strings = len(set(substring))
                    if unique_strings <= maxLetters:
                        freq_map[substring] = freq_map.get(substring, 0) + 1
                r += 1
            l += 1
            r = l
#        res = sorted([(combo,freq) for combo, freq in freq_map.items()], key = lambda x:x[1], reverse = True)
#        return res[0][1] if res else 0
        return max(freq_map.values()) if freq_map.values() else 0

109600