Count Vowel Substrings of a String - Problem

A substring is a contiguous (non-empty) sequence of characters within a string.

A vowel substring is a substring that:

  • Only consists of vowels ('a', 'e', 'i', 'o', and 'u')
  • Has all five vowels present in it

Given a string word, return the number of vowel substrings in word.

Input & Output

Example 1 — Basic Case
$ Input: word = "aeiouu"
Output: 2
💡 Note: The vowel substrings with all 5 vowels are: "aeiou" (positions 0-4) and "aeiouu" (positions 0-5). Both contain all vowels a,e,i,o,u.
Example 2 — With Consonants
$ Input: word = "unicornarihan"
Output: 0
💡 Note: No substring contains all 5 vowels. The vowel-only segments are too short: "u", "i", "o", "a", "i", "a" - none have all 5 vowels.
Example 3 — Mixed Content
$ Input: word = "cuaieuouuc"
Output: 7
💡 Note: The vowel segment "uaieuous" (positions 1-7) contains all 5 vowels. Valid substrings are: "uaieuo", "uaieuou", "uaieuouu", "aieuou", "aieuouu", "ieuouu", "aieuouu" - total of 7.

Constraints

  • 1 ≤ word.length ≤ 100
  • word consists of lowercase English letters only

Visualization

Tap to expand
Count Vowel Substrings: Find All 5 VowelsInput: "cuaieuouuc"cuaieuouucSkipVowel Segment: u,a,i,e,u,o,u,uSkip"uaieuo" - Has all 5 vowels ✓"uaieuou" - Has all 5 vowels ✓Count all substrings containing exactly 5 unique vowelsOutput: 7 valid vowel substrings found
Understanding the Visualization
1
Input Analysis
String "cuaieuouuc" with vowels and consonants
2
Find Vowel Segments
Identify continuous vowel-only sections
3
Count Valid Substrings
Count substrings with all 5 unique vowels
Key Takeaway
🎯 Key Insight: Valid substrings need exactly 5 unique vowels and no consonants
Asked in
Google 12 Amazon 8 Microsoft 6 Facebook 4
23.4K Views
Medium Frequency
~25 min Avg. Time
856 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