C++, sliding window, O(n) && O(1)
Complexity

Time complexity:
O(n)


Space complexity:
O(1)

Code
# Complexity
- Time complexity:
O(n)

- Space complexity:
O(1)

# Code
```cpp []
class Solution {
public:
    int numberOfSubstrings(string s, int k) {
        array<int, 26> counts = {0};
        int total = 0;
        size_t left = 0;
        for (size_t right = 0; right < s.size(); ++right) {
            ++counts[s[right]-'a'];
            while(atLeastK(counts, k)) {
                total += (s.size()-right);
                --counts[s[left]-'a'];
                ++left;
            }
        }
        return total;
    }

    int atLeastK(array<int, 26>& counts, int k) {
        for (size_t i = 0; i < 26; ++i) {
            if (counts[i] >= k) {
                return true;
            }
        }
        return false;
    }
};

```
['C++']