3306. Count of Substrings Containing Every Vowel and K Consonants II - Explanation

Problem Link

Description

Count the contiguous substrings of word that include each of the five vowels (a, e, i, o, and u) at least once and contain exactly k consonants. Every lowercase English letter other than these five vowels is a consonant. Substrings at different positions count separately, even when their text is identical.

Example 1:

Input: word = "aeioub"
k = 1

Output: 1

Explanation: The entire string contains every vowel and exactly one consonant, b. Removing any character from either end loses either a required vowel or the only consonant, so there is one valid substring.

Example 2:

Input: word = "aaeiou"
k = 0

Output: 2

Explanation: Both "aaeiou" and its suffix "aeiou" contain all five vowels and no consonants. These are the two valid substrings.

Example 3:

Input: word = "aeiob"
k = 0

Output: 0

Explanation: The letter u does not appear anywhere, so no substring can contain every vowel.

Constraints:

  • 5 <= word.length <= 200000
  • word contains only lowercase English letters.
  • 0 <= k <= word.length - 5


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.