Slide Window
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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 n = s.length();\n        if (k == 1) {\n            return n * (n + 1) >> 1;\n        }\n\n        int ans = 0;\n        Map<Character, Integer> map = new HashMap<>();\n        char c = \'\\0\';\n        int val = 0;\n        int prefix, suffix;\n        for (int i = 0, j = 0; i < n - 1; ++i) {\n            boolean isMatch = false;\n            while (j < n) {\n                c = s.charAt(j);\n                val = map.getOrDefault(c, 0) + 1;\n                map.put(c, val);\n                j += 1;\n\n                if (val == k) {\n                    isMatch = true;\n                    break;\n                }\n            }\n\n            if (!isMatch) {\n                break;\n            }\n\n            suffix = n - j;\n            \n            prefix = 0;\n            while (i < j) {\n                c = s.charAt(i);\n                val = map.get(c);\n                val -= 1;\n                if (val == 0) {\n                    map.remove(c);\n                } else {\n                    map.put(c, val);\n\n                    if (val == k - 1) {\n                        break;\n                    }\n                }\n\n                prefix += 1;\n                i += 1;\n            }\n\n            ans += (prefix + 1) * (suffix + 1);\n        }\n\n        return ans;\n    }\n}\n```
['Java']