278. Longest Substring with At Least K Repeating Characters

HardStringString

Given a string s and an integer k, return the length of the longest substring in which every distinct character appears at least k times. Input: '"s", k'.

Input: '"s", k'.

Output: Integer — length of the longest valid substring.

Examples

Example 1
Input: "aaabb", 3
Output: 3
Explanation: 'aaa' has a appearing 3 times.
Example 2
Input: "ababbc", 2
Output: 5
Explanation: 'ababb': a x2, b x3.
Example 3
Input: "abc", 2
Output: 0
Explanation: No char repeats twice.

Constraints

Asked by

AmazonMicrosoftGoogleBloombergMeta
Solve this problem in the editor →