Longest Substring with At Least K Repeating Characters
Problem statement
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.
If no nonempty substring satisfies the condition, return 0.
Function
longestSubstring(s: String, k: int) → intExamples
Example 1
s = "aaabb"k = 3return = 3The substring aaa contains one distinct character exactly three times.
Example 2
s = "ababbc"k = 2return = 5In ababb, a occurs twice and b occurs three times.
Example 3
s = "abc"k = 2return = 0No character repeats twice in any substring.
Constraints
0 <= s.length <= 100000.scontains only lowercase English letters.1 <= k <= 100000.