BEATS 90% || BEST BEGINNER CODE || SLIDING WINDOW || C++
Intuition\nTo find the number of substrings that contain at least \'k\' occurrences of each character, we can use the sliding window technique. By adjusting the
# Intuition\nTo find the number of substrings that contain at least \'k\' occurrences of each character, we can use the sliding window technique. By adjusting the window size based on the character counts, we can efficiently count valid substrings.\n\n# Approach\n1. Initialize a variable `res` to the total number of substrings in the string.\n2. Use a sliding window with two pointers (`i` and `j`) to explore substrings.\n3. Maintain a hashmap to count the occurrences of each character within the window.\n4. Expand the window by moving `j` and updating character counts.\n5. If a character\'s count reaches `k`, shrink the window from the left by moving `i` to exclude characters and update the count.\n6. Calculate the number of valid substrings for each position of `j` and adjust `res` accordingly.\n7. Return the final count of valid substrings.\n\n# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(1)$$ (since the hashmap will contain at most a fixed number of characters)\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n        int numberOfSubstrings(string s, int k) {\n        int n = s.length(), res = (n + 1) * n / 2;\n        unordered_map<char, int> mpp;\n        for (int i = 0, j = 0; j < n; j++) {\n            mpp[s[j]]++;\n            while (mpp[s[j]] >= k)\n                --mpp[s[i++]];\n            res -= j - i + 1;\n        }\n        return res;\n    }\n};\n```
['Hash Table', 'String', 'Sliding Window', 'C++']