C++ O(N) Time | Easy Solution
This problem can be viewed as sum of total number of substrings having index i where word[i] is vowel. Basically we have to find the count of substrings that in
This problem can be viewed as sum of total number of substrings having index i where word[i] is vowel. Basically we have to find the count of substrings that include index i (for word[i] is vowel) .\n\nE.g:- For String "abc" -> total substrings with index 0 is 3 i.e - a, ab, abc so Ans is 3\nFor String "aba" -> total substrings with index 0 is 3 and total substrings with index 2 is 3 so Ans is 6\n\nSolution Appproach:-\n\nFor each index i total substring will be -> (i+1) * (n-i)\nLets say for eg -> "abcdefgh". Here for index 4 (i.e for e) e, ef, efg, efgh, de, def ... these will be the substring so indexes before e combined with indexes after e will result in all the substring.\n\nThere will be two type of substrings that will include e. One with the letter that will start with letters coming before e and one  with those start from e itself.\n\n```\nclass Solution {\npublic:\n    long long countVowels(string word) {\n        int len = word.size();\n        \n        long long ans = 0;\n        \n        for(int i=0; i<len; i++)\n        {\n            if(word[i] == \'a\' || word[i] == \'e\' || word[i] == \'i\' || word[i] == \'o\' || word[i] == \'u\')\n            {\n                ans += (long long) (i+1) * (long long) (len-i);\n            }\n        }\n        \n        return ans;\n       \n    }\n};\n```
['String', 'C', 'Combinatorics', 'C++']