732. Count Substrings With K-Frequency Characters II
Given a string s and an integer k, determine the total number of substrings of s in which at least one character appears k or more times.
A substring is defined as a contiguous sequence of characters within the string.
Example 1:
Input : s = "aab", k = 2
Output : 2
Explanation :
The substrings that meet the condition are:
- "aa" (the character 'a' appears 2 times)
- "aab" (the character 'a' appears 2 times)
Example 2:
Input: s = "aaaa", k = 3
Output: 3
Explanation:
The valid substrings are:
- "aaa" (the first three letters; 'a' appears 3 times)
- "aaa" (the last three letters; 'a' appears 3 times)
- "aaaa" (all letters; 'a' appears 4 times)
Now Your Turn!
Pick the correct output for the given inputInput : s = "aabb", k = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ s.length ≤ 3 × 10⁵
- 1 ≤ k ≤ s.length
- s consists only of lowercase English letters.