Why it is showing Partially correct even if i have used O(n) time


#1

int vo(char a)
{
if(a==‘a’||a==‘e’||a==‘i’||a==‘o’||a==‘u’)
return 1;
else
return 0;
}
int co(char a)
{
if(a==‘a’||a==‘e’||a==‘i’||a==‘o’||a==‘u’)
return 0;
else
return 1;
}

int Solution::solve(string A) {
long count=0;
long nfv=0;
long nfc=0;
for(long i=0;i<A.size();i++)
{
if(vo(A[i]))
nfv++;
else
nfc++;
}
for(long i=0;i<A.size();i++)
{
if(vo(A[i]))
{
count=count+nfc;
nfv–;
}
else
{
count=count+nfv;
nfc–;
}
}
return count;
}


#2

you forgot to MOD the answer


#3

Please do modulus with count%1000000007 otherwise change datatype of count to long and do modulus with count%1000000007


#4

int Solution::solve(string a) {
long long count=0;
int vcount=0;
int ccount=0;
for(int i=0;i<a.size();i++)
{
if(a[i]==‘a’||a[i]==‘e’||a[i]==‘i’||a[i]==‘o’||a[i]==‘u’)
{
vcount++;
count=count+ccount;
}
else if(!(a[i]==‘a’||a[i]==‘e’||a[i]==‘i’||a[i]==‘o’||a[i]==‘u’))
{
ccount++;
count=count+vcount;
}
}
return (count%1000000007);

}