O(n) simple DP approach (based on substring ending at ith pos)
IntuitionUsing DP, We can find current answer using pre computed ansApproachWe can observe from above, if the current char is vowel, then current count will be
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Using DP, We can find current answer using pre computed ans
# Approach
<!-- Describe your approach to solving the problem. -->

![sol.png](https://assets.leetcode.com/users/images/4d75794f-e623-4a6b-baa9-2f1208fc5122_1743399688.9724035.png)


We can observe from above, if the current char is vowel, then current count will be count of vowel from previous answer + number of substring that ends at ith position (as the vowel can be added to all the substring and it will be a valid substring )+ 1. 

// if vowel --> dp[i] = 1 + (dp[i-1]+i)
// if not vowel --> dp[i] = dp[i-1]

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

O(N)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(N)
# Code
```cpp []
class Solution {
public:

    bool isVowel(char c){
        if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
            return true;
        }else{
            return false;
        }
        return false;
    }
    long long countVowels(string word) {

        int n = word.length();
        vector<long long> dp(n,0);

        if(isVowel(word[0])){
            dp[0] = 1;
        }else{
            dp[0] = 0;
        }


        for(int i=1;i<n;i++){
            if(isVowel(word[i])){
                dp[i]  = 1 + dp[i-1]+i;
            }else{
                dp[i] = dp[i-1];
            }
        }
        long long ans = 0;
        for(int i=0;i<n;i++){
            ans += dp[i];
        }
        return ans;
    }
};

if(helpful){
    do(upvote)
}


```
['Dynamic Programming', 'C++']