Beautifully Explained || Add contribution of each vowel
Explanation\n\nif words[i] is a vowel,\nthere are (i+1) choices for start of substring\nand (n-i) choices for end of substring.\nSo, total (i+1)*(n-i) substring
# Explanation\n```\nif words[i] is a vowel,\nthere are (i+1) choices for start of substring\nand (n-i) choices for end of substring.\nSo, total (i+1)*(n-i) substrings contain the vowel word[i].\n\nEx, \nConsider the string "bcaklm" (n = 6)\n\n0 1 2 3 4 5 \nb c a k l m\n\nwe have word[2] = \'a\' which is a vowel\nThere are 3(i+1) choices to start a substring i.e. \'b\', \'c\', \'a\'\nThere are 4(n-i) choices for ending a substring i.e. \'a\', \'k\', \'l\', \'m\'\n\nSo, total 3 * 4 = 12 substrings are possible which are as follows -\n1. bc\'a\'\n2. c\'a\'\n3. \'a\'\n\n4. bc\'a\'k\n5. c\'a\'k\n6. \'a\'k\n\n7. bc\'a\'kl\n8. c\'a\'kl\n9. \'a\'kl\n\n10. bc\'a\'klm\n11. c\'a\'klm\n12. \'a\'klm\n```\n# Complexity\n- Time complexity: $$O(n)$$ \n\n- Space complexity: $$O(1)$$ \n# Code\n```\nclass Solution {\n    bool isVowel(char ch) {\n        return ch == \'a\' || ch == \'e\' || ch == \'i\' || ch == \'o\' || ch == \'u\';\n    }\npublic:\n    long long countVowels(string word) {\n        long long ans = 0, n = word.length();\n\n        for(int i=0; i<n; i++) {\n            if(isVowel(word[i])) {\n                ans += 1LL*(i+1)*(n-i);\n            }\n        }\n     return ans;\n    }\n};\n```
['C++']