#395
Longest Substring with At Least K Repeating Characters
specialist · 930 · lc medium +32 · verified · 46.1% accepted · 6,709 likes · top 30%
Description
Given a string s and an integer k, locate the longest contiguous substring in which every character present has a frequency of at least k.
Return that length, or 0 if no such substring exists.
Example 1:
Input: s = "aaabb", k = 3
Output: 3
Explanation: The longest substring is "aaa", as 'a' is repeated 3 times.
Example 2:
Input: s = "ababbc", k = 2
Output: 5
Explanation: The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.
Code
1
2
3