C++ Fully explained With proof
Explanation\nFor each vowels s[i],\nit could be in the substring starting at s[x] and ending at s[y],\nwhere 0 <= x <= i and i <= y < n,\nthat is (i + 1) choice
Explanation\nFor each vowels s[i],\nit could be in the substring starting at s[x] and ending at s[y],\nwhere 0 <= x <= i and i <= y < n,\nthat is (i + 1) choices for x and (n - i) choices for y.\n\nSo there are (i + 1) * (n - i) substrings containing s[i].\nTime O(n)\nSpace O(1)\n\n\n\n\tclass Solution {\n\n\tpublic:\n\n\t\tbool isVowel(char c){\n\t\t\treturn c==\'a\' or c==\'e\' or c==\'i\' or c==\'o\' or c==\'u\';\n\t\t}\n\n\t\tlong long countVowels(string s) {\n\t\t\tlong long n = s.size();\n\t\t\tlong long sum=0;\n\t\t\tfor (long long i = 0; i < n; i++) {\n\t\t\t   if(isVowel(s[i])){\n\t\t\t\t   sum+=(i+1)*(n-i);\n\t\t\t   }\n\t\t\t}\n\t\t\treturn sum;\n\t\t}\n\t};
[]