Skip to content

3306. Count of Substrings Containing Every Vowel and K Consonants II #1414

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

The problem requires us to count the number of substrings within a given string word that contain all vowels (a, e, i, o, u) at least once and exactly k consonants. We use a sliding window approach to efficiently solve this problem within the given constraints.

Key Points

  • A substring must contain all five vowels (a, e, i, o, u) at least once.
  • It must have exactly k consonants.
  • The length of word is large (up to 200,000 characters), so an efficient solution is necessary.
  • The solution uses sliding window and two-pointer techniques to optimize the counting process.

Approach

We use the idea of: Substrings with exactly k consonants = Substrings with at most k - Substrings with at most (k-1)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Mar 10, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants