Easy c++ solution TC:O(N) SC:O(1)


#1

Space complexity is O(1) even if we are using hashset because it is constant for all cases and does not change with N.

int Solution::solve(string A) {
    int n = A.length();
    unordered_set <char> vowels = {'a','e','i','o','u','A','E','I','O','U'};
    int count = 0;
    for(int i=0; i<n; i++){
        if(vowels.find(A[i]) != vowels.end()){
            count += (n-i);
            }
        }
    return count%10003;
}