You're tasked with finding all perfect substrings in a given word. A perfect substring is one that contains every vowel (a, e, i, o, u) at least once and has exactly k consonants.
Given a string word and a non-negative integer k, return the total count of such perfect substrings.
Example: For word = "aeioqq" and k = 2, the substring "aeioqq" contains all vowels (a, e, i, o) and exactly 2 consonants (q, q), making it a perfect substring.
This problem tests your ability to efficiently track character frequencies while exploring all possible substring combinations using advanced string manipulation techniques.
Input & Output
Visualization
Time & Space Complexity
Each character is visited at most twice (once by right pointer, once by left pointer)
Only using constant extra space for vowel and consonant counters
Constraints
- 1 โค word.length โค 105
- 0 โค k โค word.length
- word consists only of lowercase English letters
- All vowels must be present at least once
- Exactly k consonants are required