C++ || Logic Explained || DP
Intution:\n\nThe main idea is how the current substring will behave when a new character will be added.\nSuppose we have S = {a,b,c}  and u is added so total vo
***Intution:***\n\nThe main idea is how the current substring will behave when a new character will be added.\nSuppose we have **S = {a,b,c}**  and **u** is added so total vowels in S becomes 2, if a consonant is added No change is reflected.\n\n***Building the solution:***\n\n![image](https://assets.leetcode.com/users/images/35b2b593-534b-4503-963b-b3b7560e576a_1643618336.8590808.png)\n\n***Code***\n\n```\n long long countVowels(string s) {\n        int n = s.size();\n        long long sum=0, dp[n];\n\n        if(s[0]==\'a\'||s[0]==\'e\'||s[0]==\'i\'||s[0]==\'o\'||s[0]==\'u\') \n\t\t\tdp[0] =  1;\n        \n        else\n\t\t\tdp[0] = 0;\n        \n        sum += dp[0];\n        \n        for(int i=1;i<n;i++){\n  \n            if(s[i]==\'a\'||s[i]==\'e\'||s[i]==\'i\'||s[i]==\'o\'||s[i]==\'u\') \n                dp[i] = dp[i-1]+i+1;\n            \n            else \n                dp[i] = dp[i-1];\n            \n            sum += dp[i];\n        }\n        \n        return sum; \n    }\n```\n**Questions are welcome**\n\nPS:  Please forgive me for the handwriting.
['Dynamic Programming']