← Questions

Count substrings that use only vowels and contain all five

0
SnowflakeCoding

Given a string s of lowercase English letters, return the number of contiguous substrings that satisfy both rules:

  1. Every character of the substring is a vowel (a, e, i, o, u).
  2. The substring contains each of the five vowels at least once.

Substrings are counted by position: two equal substrings that start at different indices both count.

Implement:

def count_vowel_substrings(s: str) -> int: ...

Constraints

  • 0 <= len(s) <= 10^5
  • s contains only lowercase English letters.
  • The answer can exceed 32 bits.

Start with a working solution, then aim for linear time.

Example 1

Input:  s = "aaeiou"
Output: 2

The valid substrings are "aaeiou" and "aeiou".

Example 2

Input:  s = "aeioxuaei"
Output: 0

The x splits the vowels into "aeio" and "uaei", and neither part contains all five vowels.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding