C++ O(N) | O(1)
generating all substrings will take O(N^2) .\nBut length constraints are too high. So we need to find a better approach..\nwhat if we can find count of substrin
generating all substrings will take O(N^2) .\nBut length constraints are too high. So we need to find a better approach..\nwhat if we can find count of substrings the charecter is in.\ntake for example \ns= abca\ncharecter b can be present in \nb\nbc \nbca\nbut also rememeber it can also be present in substring with charecters before it.\nso   ab\n\t\tabc\n\t\tabca\nif we look at this pattern, we can see that we can multiply the number of charecters before it with the susbtring generated from \nb i.e ("b","bc","bca") so it will be 2 * 3 =6;\n\nsimilarly for charecter c \nwe can start with c , can start with bc and also abc . For all three of these substrings(before and including c)  we can calculate # of string after c;\nafter c-\nc\nca\n\nbefore c -\nbc\nbca\nabc\nabca\n\n\nthus \nposition of c * string after c = total number of strings the charecter c is in.\n\nNow we just check if the charecter is vowel or not and just only add that result to end result.\n\n\n```\nclass Solution {\npublic:\n    long long countVowels(string word) {\n        long long ans=0;\n        for(int i=0;i<word.size();i++)\n        {\n            if(word[i]==\'a\'||word[i]==\'e\'||word[i]==\'o\'||word[i]==\'u\'||word[i]==\'i\')\n                ans+=(word.size()-i)*(i+1);\n        }\n        return ans;\n    }\n};\n```
['Greedy', 'Combinatorics']