intcountVowelSubstrings(string word){ int res = 0, n = word.size(); for (int i = 0; i < n; ) { char& c = word[i]; if (vowels.contains(c)) { int start = i; while (i < n && vowels.contains(word[i])) { i++; } res += helper(word, start, i); } else { i++; } } return res; }
inthelper(string& word, int start, int end){ map<char, int> count; int left = start, right = start, res = 0; while (right < end) { count[word[right]]++; while (count.size() >= 5) { res += end - right; char& l = word[left++]; count[l]--; if (count[l] == 0) { count.erase(l); } } right++; } return res; } };