Python3 solution | explained | sliding window
IntuitionSliding windowApproachConstruct a frequency hashmap to maintain the numbers for each letter. The number of elements in the dictionary will always be 26
# Intuition
Sliding window

# Approach
Construct a frequency hashmap to maintain the numbers for each letter. The number of elements in the dictionary will always be 26 at maximum. We will get the number of numbers wich have freq >= k at every iteration and based on that add it to the count. We always only need 1 element with freq >= k when counting, so we will leverage that.

# Complexity
- Time complexity:
O(n) | n = len(s) * 26 

- Space complexity:
O(1) since we use only the dictionary with 26 max keys

# Code
```python3 []
class Solution:
    def numberOfSubstrings(self, s: str, k: int) -> int:
        j = 0
        d = defaultdict(lambda: 0)
        count = 0

        for i in range(len(s)):
            d[s[i]] += 1
            k_elements = 0

            for _, element in enumerate(d):
                if d[element] >= k:
                    k_elements += 1
            
            if k_elements > 0:
                count += j + 1
                # if it's only 1 element with freq == k and d[s[j]] < k it means s[j] is not that element and we can delete it
                # if it's only 1 element with freq == k and d[s[j]] > k it means s[j] is that element and we can delete since it's still >= k as freq
                while j < i and (k_elements >= 2 or k_elements == 1 and d[s[j]] != k):
                    d[s[j]] -= 1
                    if d[s[j]] == k - 1:
                        k_elements -= 1
                    count += 1
                    j += 1
        return count
```
['Sliding Window', 'Python3']