Easy Explained || O(n) || Two Pointer Approach
Approach:\n\nWe can solve this problem using the sliding window (or two-pointer) technique along with character frequency counting. The main idea is to maintain
# Approach:\n\nWe can solve this problem using the **sliding window** (or two-pointer) technique along with character frequency counting. The main idea is to maintain a window `[i, j]` such that `s[j]` in the window appears `k` times.\n\n# Steps:\n\n1. **Sliding Window Setup:**\n   - Use two pointers `i` and `j` to represent the window.\n   - We use an array `ccount[26]` to track the frequency of each character in the window.\n\n2. **Main Logic:**\n   - increment `s[j]` frequency in `ccount`.\n   - If the frequency of `s[j]` is greater than or equal to `k`, this means we have found a valid substring from `i` to `j`. \n    - Add the count of all possible substrings starting from `i` and ending at `j` to `n-1` (since any further extension of this substring `i...j` will also be valid). The number of such substrings is `n - j`.\n    - increase `i` pointer till `ccount[s[j]] >= k`.\n\n# Complexity\n- Time complexity:\n\nWe are traversing the array one time via `i and j` pointers. So the time complexity is $$O(n)$$.\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nConstant extra space `int[26]` is used so the space complexity is $$O(1)$$.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int numberOfSubstrings(string s, int k) {\n        int ccount[26] = {0};\n        int i=0,j=0;\n        int count = 0, n = s.size();\n\n        while(j<n) {\n            int c=s[j]-\'a\';\n            ccount[c]++;\n            while(ccount[c]>=k) {\n                count += n-j;\n                ccount[s[i]-\'a\']--;\n                i++;\n            }\n            j++;\n        }\n        return count;\n    }\n};\n```\n\n# Please Upvote
['C++']