⚠️ INTUITIVE EASY SOLUTION
\n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n \n\n\n\n# \u2B50 Intuition\nThe problem asks to count all substrings where at least one charact
<div align="center">\n\n# \uD83D\uDC93**_PLEASE CONSIDER UPVOTING_**\uD83D\uDC93\n\n</div>\n\n***\n\n# \u2B50 Intuition\nThe problem asks to count all substrings where at least one character appears at least `k` times. The key observation here is that, given a sliding window approach, once we find a substring where a character appears `k` times, extending this substring by adding more characters will still satisfy the condition.\n\n# \u2B50 Approach\n1. **Sliding Window**:\n   - We use a sliding window approach with two pointers, `l` (left) and `r` (right). The `r` pointer expands the window by adding new characters, while the `l` pointer contracts the window when a valid substring is found.\n   \n2. **Frequency Map**:\n   - Maintain a frequency map `map` that keeps track of character frequencies within the current window `[l, r]`.\n   \n3. **Counting Valid Substrings**:\n   - For every right pointer `r`, we increment the frequency of the character at `s[r]` in the map.\n   - If any character in the map has a frequency greater than or equal to `k`, all substrings starting from the current left pointer `l` up to the current right pointer `r` are valid.\n   - When we find such valid substrings, we increment the count by `len - r` (which represents all possible valid substrings from the current window).\n   - We then increment `l` to contract the window and continue searching for new substrings.\n\n4. **Return the Count**:\n   - After the sliding window has processed the entire string, return the total count of valid substrings.\n\n# \u2B50 Complexity\n- **Time complexity**:  \n  The time complexity is **O(n)**, where `n` is the length of the string. Both pointers `l` and `r` traverse the string at most once.\n\n- **Space complexity**:  \n  The space complexity is **O(n)** due to the frequency map, which can store up to `n` characters in the worst case (if all characters in the string are distinct).\n\n# \u2B50 Code\n```java []\nclass Solution {\n    public int numberOfSubstrings(String s, int k) {\n        int count = 0;\n        Map<Character, Integer> map = new HashMap<>();\n\n        int l = 0, r = 0, len = s.length();\n\n        while (r < len) {\n            char ch = s.charAt(r);\n            map.put(ch, map.getOrDefault(ch, 0) + 1);\n\n            while (map.getOrDefault(ch, 0) >= k && l <= r) {\n                count += len - r;\n\n                char leftChar = s.charAt(l++);\n                map.put(leftChar, map.get(leftChar) - 1);\n                if (map.get(leftChar) == 0) map.remove(leftChar);\n            }\n\n            r++;\n        }\n\n        return count;\n    }\n}\n```
['Sliding Window', 'Java']