Vowel Complete Substrings
MediumSliding Window · Snowflake
You are given a lowercase string s. A substring is vowel-complete when:
- every character in it is a vowel (
a,e,i,o,u), and - each of the five vowels appears in it at least once.
Return the number of vowel-complete substrings of s. Substrings are counted by position: two substrings with the same text but different start or end indices are counted separately.
A consonant can never be part of a vowel-complete substring, so it splits s into independent vowel-only runs.
Example 1
- Input:
- s = "uaeiouu"
- Output:
- 5
- Explanation
- Every substring that contains the core
aeiou(indices 1 to 5) is complete. It may start at index 0 or 1 and end at index 5 or 6, giving 4. The substringuaeio(indices 0 to 4) is also complete, since it already holds all five vowels, for a total of 5.
Example 2
- Input:
- s = "aeixou"
- Output:
- 0
- Explanation
- The
xsplits the string intoaeiandou. Neither run contains all five vowels, and no counted substring may cross the consonant, so the answer is 0.
Example 3
- Input:
- s = "aaeiou"
- Output:
- 2
- Explanation
- The complete substrings must end at the final
uand start at index 0 or 1 (both starts still include ana), givingaaeiouandaeiou, so 2.
Constraints
0 <= s.length <= 10^5sconsists of lowercase English letters