My C++ solution using single pass


#1

Trick is to find the formula for number of strings.

bool isVowel(char A)
{
A = tolower(A);
return (A == 'a') || (A == 'e') || (A == 'i') || (A == 'o') || (A == 'u');
}

int Solution::solve(string A)
{
long cnt = 0;
const int n = A.length();

for(int i=0; i<n; i++)
{
if (isVowel(A[i]))
{
cnt = cnt + n-(i);
}
}

return cnt % 10003;
}