Ctrl K

Every Vowel and k Consonants

Medium
You are given a string text of lowercase English letters and an integer k. Count the contiguous substrings of text in which each of the vowels a, e, i, o, u appears at least once and which contain exactly k consonants. Any letter other than those five is a consonant. Substrings at different positions are counted separately, even if they read the same.
Example 1
text="banaeiou", k=1 → 2

"anaeiou" and "naeiou" both have all five vowels and exactly one consonant, n. The whole string does not count: it has two consonants.

Example 2
text="aeiouu", k=0 → 2

No consonants and every vowel: "aeiou" and "aeiouu".

Example 3
text="xaeioy", k=1 → 0

There is no u anywhere, so no piece qualifies.

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="banaeiou", k=1
Expected
2

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