Intuitive Python solution - using template
Approach\n\nIn short, we record each VALID substrings and their occurrence and return their max occ. \n\nUsing sliding window template to solve this problem. Ha
# Approach\n\nIn short, we record each VALID substrings and their occurrence and return their max occ. \n\nUsing sliding window template to solve this problem. Having left and right index. We update the occurrence of specific substring when it meets the conditions, and we need to shrink the window when its length is in the required range.\n\n\n# Code\n```python3\nclass Solution:\n    def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n        left = 0\n        result = defaultdict(int)\n        freqs = defaultdict(int)\n        for right, num in enumerate(s):\n            freqs[num] += 1\n            while (right - left + 1) >= minSize and (right - left + 1) <= maxSize:\n                if len(freqs) <= maxLetters:\n                    result[s[left:right + 1]] += 1\n                freqs[s[left]] -= 1\n                if not freqs[s[left]]:\n                    freqs.pop(s[left])\n                left += 1\n                \n        return max(result.values()) if result else 0\n```
['Sliding Window', 'Python3']