sliding window beats 100%
IntuitionApproach

Initialize sliding window:

Use unordered_map m to track character frequencies.
Set left = 0, and count = 0 for valid substrings.



Expand t
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

1. **Initialize sliding window**:
   - Use `unordered_map m` to track character frequencies.
   - Set `left = 0`, and `count = 0` for valid substrings.

2. **Expand the window from left to right**:
   - For each character `s[i]`, increment its frequency in `m`.

3. **When current character occurs `k` times**:
   - Every substring from current `i` to end (`n-i` substrings) is valid.
   - Shrink the window from the left until `m[s[i]] < k`.

4. **Return total count** of such valid substrings.


# Complexity
- Time complexity:O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int numberOfSubstrings(string s, int k) {
        unordered_map<int,int>m;
        int n=s.length();
        int count=0;
        int left=0;
        for(int i=0;i<n;i++)
        {
            m[s[i]]++;
            while(m[s[i]]==k)
            {
                count+=n-i;
                m[s[left]]--;
                left++;
            }
        }
        return count;
    }
};
```
['C++']