C++ and Python | Most Efficient Solution | Sliding Window, Hash Table and Set | Clear & Concise
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n**C++ Solution:-**\n```\nclass Solution {\npublic:\n    int maxFreq(string s, int maxLetters, int minSize, int maxSize) {\n        map<string, int> hashmap;\n        int n = s.size();\n        int ans = 0;\n        int size = n-minSize;\n        for (int i=0; i<=size; i++) {\n            hashmap[s.substr(i,minSize)]++;\n        }\n        for (auto &str:hashmap) {\n            set<char> subs(begin(str.first),end(str.first));\n            if (subs.size() <= maxLetters) {\n                ans = max(ans, str.second);\n            }\n        }\n        return ans;\n    }\n};\n```\n**Python Solution:-**\n```\nclass Solution:\n    def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:\n        hashmap = {}\n        for i in range(len(s)-minSize+1):\n            hashmap[s[i:i+minSize]] = 0\n        for i in range(len(s)-minSize+1):\n            hashmap[s[i:i+minSize]] += 1\n        ans = 0\n        for key, val in hashmap.items():\n            if len(set(key)) <= maxLetters:\n                ans = max(ans, val)\n        return ans\n```
['Hash Table', 'Sliding Window', 'Python', 'C++']