Easy Understanding C++ Solution || O(n) Time Complexity
Thought Process:\nLet\'s take a word "barcode"\nWe need to find total number of occurance of vowels i.e. [a,o,e]\n1. Let\'s Try to make substrings that gonna in
**Thought Process:**\nLet\'s take a word "barcode"\nWe need to find total number of occurance of vowels i.e. [a,o,e]\n1. Let\'s Try to make substrings that gonna include \'a\'.\n\t* \tsubstrings starting from \'b\' are: "ba", "bar", "barc", "barco", "barcod", "barcode" \n\t\t* \tit means we need to make substrings where the last letter is [a, ...]\n\t* \tsubstrings starting from \'a\' are: "a",  "ar", "arc", "arco", "arcod", "arcode"\n\t\t* \tit also says we need to make substrings where the last letter is [a, ...]\n\t* \tSo, to include \'a\', we need substring that starts with letter which is on or before \'a\' and ends with letter which is on or after \'a\'.\n\t* \tCount of \'a\' = 2*6 = 12.\n2. Let\'s Try to make substrings that gonna include \'o\'.\n\t* \tsubstrings starting from \'b\' are: "barco", "barcod", "barcode" \n\t\t* \tit means we need to make substrings where the last letter is [o, ...]\n\t* \tsubstrings starting from \'a\' are: "arco", "arcod", "arcode"\n\t\t* \tit also says we need to make substrings where the last letter is [o, ...]\n\t* \tsubstrings starting from \'r\' are: "rco", "rcod", "rcode" \n\t\t* \tit also says we need to make substrings where the last letter is [o, ...]\n\t* \tsubstrings starting from \'c\' are: "co", "cod", "code"\n\t\t* \tit also says we need to make substrings where the last letter is [o, ...]\n\t* \tsubstrings starting from \'o\' are: "o", "od", "ode"\n\t\t* \tit also says we need to make substrings where the last letter is [o, ...]\n\t* \tSo, to include \'o\', we need substring that starts with letter which is on or before \'o\' and ends with letter which is on or after \'o\'.\n\t* \tCount of \'a\' = 3*5 = 15.\n* So, from the above observation, we can say that to include any vowel, we need **(pos[vowel]+1)**, **(len-pos[vowel])** number of different substrings i.e. that much number of occurrence of the vowel.\n*  Here, **len** is **length of word** and **pos** is **position of vowel**.\n\n**Code:**\n```\nlong long countVowels(string word){\n    int len=word.length();\n    long long count=0;\n    for(int pos=0; pos<len; pos++){\n        char c = word[pos];\n        if(c==\'a\' || c==\'e\' || c==\'i\' || c==\'o\' || c==\'u\'){\n            count += 1ll*(n-pos)*(pos+1);\n        }\n    }\n    return count;\n}\n```\n**Time Complexity: O(n)\nSpace Complexity: O(1)\nUpvote if you find it helpful, Comment For any explanation...**
['C', 'C++']