Medium

Quiz

#395 Longest Substring with At Least K Repeating Characters

APPROACH

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.
1 of 4
1:00

What is the optimal approach for this problem?