Input: word ="aeioqq", k =1Output: 0Explanation:
There is no substring with every vowel.
Example 2:
1
2
3
4
5
6
7
8
Input: word ="aeiou", k =0Output: 1Explanation:
The only substring with every vowel and zero consonants is`word[0..4]`, which
is`"aeiou"`.
Example 3:
1
2
3
4
5
6
7
Input: word ="ieaouqqieaouqq", k =1Output: 3Explanation:
The substrings with every vowel and one consonant are:*`word[0..5]`, which is`"ieaouq"`.*`word[6..11]`, which is`"qieaou"`.*`word[7..12]`, which is`"ieaouq"`.
Use the Sliding Window Technique: We maintain a window ([leftPointer, rightPointer]) over the string and expand or shrink it based on the problem’s constraints:
Expand the window by moving rightPointer and updating counts for vowels or consonants.
Shrink the window by moving leftPointer if excess consonants are present (> k).
Track Key Metrics:
distinctVowelCount: Number of unique vowels in the current window.
vowelCount[0]: Tracks consonant count. Other indices in vowelCount track counts of vowels (a, e, i, o, u).
Check Valid Substrings:
A substring is valid when:
All 5 vowels are present (distinctVowelCount == 5).
Exactly k consonants (vowelCount[0] == k).
Count Valid Substrings Using midPointer: When the window is valid:
Use midPointer to efficiently count substrings starting from leftPointer and ending at each valid position.
Finally:
Initialise leftPointer, midPointer, distinctVowelCount, vowelCount, and result.
Iterate through the string with rightPointer, processing each character:
Update vowel and consonant counts.
Shrink the window if consonant count exceeds k.
Count valid substrings when the window satisfies the constraints.