Use hashmap, only store subs which satisfy the maxLetters
Intuition\nFirstly, you can ignore the maxSize. Why ?\nA window with repeated maxSize will always satisfy its prefix and minSize of that repeated maxSize substr
# Intuition\nFirstly, you can ignore the maxSize. Why ?\nA window with repeated maxSize will always satisfy its prefix and minSize of that repeated maxSize substring would be a prefix. If we can already satisfy the prefix so why even bother moving any further. Also, with minSize, our substring size will be small and have greater possibility of having more of it occurence as len(s)/minSize > len(s)/maxSize. So by ignoring the maxSize you can easily solve this.\nWe create a counter of substring of length minSize and we check if it satisfy the maxLetters. If that window does then we add that to our counter. \nThen the answer would be the substring with the max count. \n\n# Complexity\n- Time complexity:\nO(n * minSize)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nclass Solution:\n    def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n\n        subs = {0:0}\n\n        for i in range(len(s)-minSize +1):\n\n            sub = s[i:i+minSize]\n            set_s = set(sub)\n            if len(set_s) <= maxLetters:\n                subs[sub] = subs.get(sub,0) + 1\n        \n        return max(subs.values())\n```\n\n# using two dics and no set for each substring\n\n```\nclass Solution:\n    def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n\n        subs = {0:0}\n        #rolling sub string count\n        u = {}\n\n        #we get the first substring count\n        for i in range(minSize-1):\n            l = s[i]\n            u[l] = u.get(l,0) + 1            \n\n        for i in range(len(s)-minSize +1):\n                   \n            sub= s[ i : i+minSize]\n            #get the last char of current sub and add to the rolling count            \n            last = sub[-1]\n\n            # setting the last\n            u[last] = u.get(last,0) + 1\n\n            # keys\n            set_s = u.keys()\n            \n            #condition       \n            if len(set_s) <= maxLetters:\n                subs[sub] = subs.get(sub,0) + 1\n            \n            #now we remove the ith letter to get the the rolling count ready for the next sub\n            u[s[i]] -= 1\n            if u[s[i]] == 0:\n                #takes O(1)\n                del u[s[i]]            \n        \n        return max(subs.values())\n```
['Hash Table', 'Python3']