C++, Easily explained
Intuition\n Describe your first thoughts on how to solve this problem. \nWe can solve this problem by finding all substrings of the given string and count total
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe can solve this problem by finding all substrings of the given string and count total no of vowels. But it will take O(2^n) complexity so it will not work.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInstead of finding all substrings and counting vowels we can traverse each character and if it is vowel then we can find the no of substrings in which this character will be present. And this is easy. As an example, let the string is \'fbacd\' and we have to find the no of substrings in which \'a\' will be present. \n    See carefully the substrings are\n ss = {\'a\', \'ac\', \'acd\', \n\'ba\', \'bac\', \'bacd\',\n\'fba\', \'fbac\', \'fbacd\' }\nAt first we will find how many character present at right side from the current character including that character. here it is 3 {a, c, d}\nand how many are in the left side including that character is 3 {f, b, a}\nSo the total substrings are 3 * 3 = 9 which are present in ss.\nSimilarly in "rabbit", \'a\' present in 2 * 5=10 substrings.\nSo for a given string we will traverse each character and if it is vowel then we will calculate the total no of substrings by above process and add it with result.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nTo traverse each character it will take O(n) time and to find the no of substrings it will take O(1) time. So total time complexity is O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nHere We are not using any extra space. So Space complesity is O(1)\n\n# Code\n```\nclass Solution {\npublic:\n    long long countVowels(string word) {\n        int n = word.size();\n        long long res = 0;\n        for(int i=0; i<n; i++){\n            if(word[i]==\'a\' || word[i]==\'e\' || word[i]==\'i\' || word[i]==\'o\' || word[i]==\'u\')\n            {\n                res += (long long)(n-i)*(long long)(i+1);\n            }\n        }\n        return res;\n    }\n};\n```
['C++']