Count Substrings With K-Frequency Characters I - Problem
Given a string s and an integer k, return the total number of substrings of s where at least one character appears at least k times.
A substring is a contiguous non-empty sequence of characters within a string.
Input & Output
Example 1 — Basic Case
$
Input:
s = "abccc", k = 3
›
Output:
3
💡 Note:
Substrings with at least one character appearing ≥3 times: "ccc" (position 2-4), "bccc" (position 1-4), "abccc" (position 0-4). The character 'c' appears 3+ times in each. Total: 3 substrings.
Example 2 — No Valid Substrings
$
Input:
s = "aaab", k = 4
›
Output:
0
💡 Note:
No character appears 4 or more times in any substring. Maximum frequency is 3 for 'a' in "aaab".
Example 3 — Single Character
$
Input:
s = "aaaa", k = 2
›
Output:
6
💡 Note:
Substrings of length ≥2 where 'a' appears ≥2 times: "aa" appears 3 times (positions 0-1, 1-2, 2-3), "aaa" appears 2 times (positions 0-2, 1-3), "aaaa" appears 1 time (position 0-3). Total: 6 substrings.
Constraints
- 1 ≤ s.length ≤ 3000
- 1 ≤ k ≤ s.length
- s consists of only lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code