Back to course home
0% completed
Vote For New Content
Longest Substring with At Least K Repeating Characters (medium)
Problem Statement
Given a string s
and an integer k
, return the maximum length
of the substring where each character appears at least k
times. If no such substring exists, return 0.
Examples
Example 1:
- Input: s =
"aaabbcc"
,k = 2
- Output:
7
- Justification: The longest substring is
"aaabbcc"
, where each character ('a', 'b', and 'c') appears at least 2 times.
Example 2:
- Input: s =
"ababbc"
,k = 3
- Output:
0
- Justification: There is no substring exists having each character frequency at least 3.
Example 3:
- Input: s =
"abcdef"
,k = 1
- Output:
6
- Justification: The entire string
"abcdef"
is the longest substring, as each character appears at least once.
Constraints:
- 1 <= s.length <= 10<sup>4</sup>
- s consists of only lowercase English letters.
- 1 <= k <= 10<sup>5</sup>
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
Table of Contents
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible
Contents are not accessible