Count of Substrings Containing Every Vowel and K Consonants I - Problem

You are given a string word and a non-negative integer k.

Return the total number of substrings of word that contain every vowel ('a', 'e', 'i', 'o', and 'u') at least once and exactly k consonants.

Input & Output

Example 1 — Basic Case
$ Input: word = "aeioqq", k = 1
Output: 0
💡 Note: No substring contains all vowels (a,e,i,o,u) and exactly 1 consonant. Missing vowel 'u'.
Example 2 — Valid Case
$ Input: word = "aeiou", k = 0
Output: 1
💡 Note: The substring "aeiou" contains all vowels and exactly 0 consonants.
Example 3 — Multiple Valid
$ Input: word = "aeiouc", k = 1
Output: 1
💡 Note: The substring "aeiouc" contains all vowels (a,e,i,o,u) and exactly 1 consonant (c).

Constraints

  • 1 ≤ word.length ≤ 1000
  • 0 ≤ k ≤ word.length
  • word consists only of lowercase English letters

Visualization

Tap to expand
Count Substrings: "aeiou" with k=0aeiouInput: word="aeiou", k=0Valid Substrings"aeiou" ✓ (all vowels, 0 consonants)"aeiou" ✗ (not all substrings valid)"aeio" ✗ (missing u)"a" ✗ (missing e,i,o,u)Only full string matches criteriaOutput: 1
Understanding the Visualization
1
Input
String word and integer k
2
Process
Find all substrings with all vowels and exactly k consonants
3
Output
Count of valid substrings
Key Takeaway
🎯 Key Insight: Use sliding window to efficiently track character counts and avoid redundant substring generation
Asked in
Google 15 Microsoft 12 Amazon 10
8.5K Views
Medium Frequency
~25 min Avg. Time
340 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen