A tune is written as a string tune of note names, each one of the seven letters 'a' to 'g'. A student may practise any passage, meaning a run of consecutive notes. A passage is well-rehearsed if every note that occurs in it occurs at least k times in it.
Return the length of the longest well-rehearsed passage, or 0 if there is none.
Examples
Input: tune = "abaccc", k = 2
Output: 3
Explanation: "ccc" works. "abac" and "abaccc" fail because "b" occurs once.
Input: tune = "aabbc", k = 2
Output: 4
Explanation: "aabb"; adding the lone "c" would break it.
Input: tune = "gfgfeggf", k = 3
Output: 0
Constraints
0 <= len(tune) <= 5 * 10**4tunecontains only letters from'a'to'g'1 <= k <= 10**5- Target complexity: O(7 · n). Checking every passage (O(n²)) is too slow for the largest tests.
Goals
- Recognise a window rule that is not monotone as the window grows
- Restore monotonicity by fixing the number of distinct values and running one window per choice