Ctrl K

Vowel-Complete Windows

Medium
A linguist is studying a long text text written in lowercase English letters with no spaces. They care about contiguous fragments that contain each of the vowels a, e, i, o, u at least once and exactly k consonants. A consonant is any letter other than those five vowels. Return the number of such fragments. Fragments at different positions count separately, even if their letters match. The text is long, so checking every fragment will be too slow.
Example 1
text="sequoia", k=1 → 1

Only "equoia" works: all five vowels and the single consonant q. Adding the s makes two consonants.

Example 2
text="ouiaexe", k=1 → 2

Both substrings start at the first letter: "ouiaex" and "ouiaexe". Each has one consonant, x.

Example 3
text="taeioutt", k=2 → 2

"taeiout" and "aeioutt", each with exactly two consonants.

Constraints
  • 5 ≤ len(text) ≤ 2·10⁵
  • text consists of lowercase English letters
  • 0 ≤ k ≤ len(text) − 5
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Repeat-Free Stretch MediumTwo-Letter Stretch MediumRecurring Gene Windows MediumWindow with Few Kinds of Letters MediumEvery Letter at Least k Times Medium
loading Python…
Input
text="sequoia", k=1
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 71 tests on the server, hidden ones included.