2063. Vowels of All Substrings Medium

@problem@discussion
#Math#String#Dynamic Programming#Combinatorics



1/**
2 * [2063] Vowels of All Substrings
3 *
4 * Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word.
5 * A substring is a contiguous (non-empty) sequence of characters within a string.
6 * Note: Due to the large constraints, the answer may not fit in a signed 32-bit integer. Please be careful during the calculations.
7 *  
8 * Example 1:
9 * 
10 * Input: word = "aba"
11 * Output: 6
12 * Explanation: 
13 * All possible substrings are: "a", "ab", "aba", "b", "ba", and "a".
14 * - "b" has 0 vowels in it
15 * - "a", "ab", "ba", and "a" have 1 vowel each
16 * - "aba" has 2 vowels in it
17 * Hence, the total sum of vowels = 0 + 1 + 1 + 1 + 1 + 2 = 6. 
18 * 
19 * Example 2:
20 * 
21 * Input: word = "abc"
22 * Output: 3
23 * Explanation: 
24 * All possible substrings are: "a", "ab", "abc", "b", "bc", and "c".
25 * - "a", "ab", and "abc" have 1 vowel each
26 * - "b", "bc", and "c" have 0 vowels each
27 * Hence, the total sum of vowels = 1 + 1 + 1 + 0 + 0 + 0 = 3.
28 * 
29 * Example 3:
30 * 
31 * Input: word = "ltcd"
32 * Output: 0
33 * Explanation: There are no vowels in any substring of "ltcd".
34 * 
35 *  
36 * Constraints:
37 * 
38 * 	1 <= word.length <= 10^5
39 * 	word consists of lowercase English letters.
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/vowels-of-all-substrings/
45// discuss: https://leetcode.com/problems/vowels-of-all-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn count_vowels(word: String) -> i64 {
51        
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_2063() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.