Longest Substring with At Least K Repeating Characters

Given a string s and an integer k, return the length of the longest substring of s such that the frequency of each character in this substring is greater than or equal to k.

If no such substring exists, return 0.

Example 1
Inputs = "aaabb", k = 3
Output3
The longest substring is "aaa", as 'a' is repeated 3 times.
Example 2
Inputs = "ababbc", k = 2
Output5
The longest substring is "ababb", as 'a' is repeated 2 times and 'b' is repeated 3 times.

Constraints

  • 1 <= s.length <= 10^4
  • s consists of only lowercase English letters.
  • 1 <= k <= 10^5

Asked at 9 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate