Vowels of All Substrings

Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.

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

Note: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.

Example 1
Inputword = "aba"
Output6
All possible substrings are "a", "ab", "aba", "b", "ba", and "a"; their vowel counts sum to 6.
Example 2
Inputword = "abc"
Output3
All possible substrings are "a", "ab", "abc", "b", "bc", and "c"; their vowel counts sum to 3.

Constraints

  • 1 <= word.length <= 10^5
  • word consists of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate