Sliding window approach with O(n) TC and O(1) SC
Intuition\nSince its a substring problem, the intuition is to use sliding window\n\n# Approach\nEvery time a valid substring is found, all the characters after 
# Intuition\nSince its a substring problem, the intuition is to use sliding window\n\n# Approach\nEvery time a valid substring is found, all the characters after the end of that substring is still valid until the end of the given string. \nEx: abacb and k = 2,\nif, "aba" substring is valid\nthen all the substrings till the end of the string is valid,\ni.e, aba, abac, abacb\n\nso add these to the result with,\nresult += s.length() - end of current valid substring\n\n# Complexity\n- Time complexity:\nO(n)\n\n- Space complexity:\nO(1)\n\n# Code\n```java []\nclass Solution {\n    public int numberOfSubstrings(String s, int k) {\n        int left = 0;\n        int result = 0;\n        int[] count = new int[26];\n\n        for(int i = 0; i< s.length(); i++) {\n            char ch = s.charAt(i);\n            count[ch -\'a\']++;\n\n            while(count[ch - \'a\'] == k) {\n                result += s.length() - i;\n                char atLeft = s.charAt(left);\n                count[atLeft - \'a\']--;\n                left++;\n            }\n        }\n\n        return result;\n    }\n}\n\n//TC: O(N)\n//SC: O(1)\n```
['Sliding Window', 'Java']