Imagine you're a linguist analyzing the vowel density of every possible phrase within a word. Your task is to calculate the total sum of vowels across all possible substrings of a given word.
A substring is any contiguous sequence of characters within the string. For example, the word "abc" has substrings: "a", "b", "c", "ab", "bc", and "abc".
The vowels we're counting are: 'a', 'e', 'i', 'o', 'u' (case-sensitive).
Goal: Return the sum of vowel counts in every substring of the input word.
Note: Due to large constraints, use 64-bit integers to avoid overflow.
Input & Output
Visualization
Time & Space Complexity
Single pass through the string, constant time calculation per character
Only using a few variables, no extra data structures needed
Constraints
- 1 โค word.length โค 105
- word consists of lowercase English letters only
- Answer may exceed 32-bit integer range - use 64-bit integers