Python 5-line solution with explanation
from collections import defaultdict\n\n There is no need to check all different valid length of substrings. Instead, we only need to check the minSize. \n Let\'
from collections import defaultdict\n\n* There is no need to check all different valid length of substrings. Instead, we only need to check the minSize. \n* Let\'s say if we have minSize = 3, maxSize = 10. if we find "abaaabaa" occurs 5 times, then "aba" occurs at least 5 times.\n\nclass Solution:\n\n    def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n        d = defaultdict(int)\n        for i in range(len(s)-minSize+1):\n            if len(set(s[i:i+minSize]))<=maxLetters:\n                d[s[i:i+minSize]] +=1\n        return max(d.values()) if d else 0
['Python']