Sliding window, O(n) java solution
Complexity\n- Time complexity:O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity:O(1)\n Add your space complexity here, e.g. O(n) \n\n# Code
# Complexity\n- Time complexity:O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int numberOfSubstrings(String s, int k) {\n        int result = 0, n = s.length(), start = 0;\n        int countChar[] = new int[26];\n        for (int i = 0; i < n; i++) {\n            char c = s.charAt(i);\n            countChar[c - \'a\']++;\n            while (countChar[c - \'a\'] >= k) {\n                result += n-i;\n                countChar[s.charAt(start++) - \'a\']--;\n            }\n        }\n        return result;\n    }\n}\n```
['Java']