Partially correct solution


#1

Why is it showing partial correct answer?

bool areless(int a, vector &A)
{
int i=0;
while(A[i]<a)
{
i++;
}
if(A[i]==a)
{
return 1;
}
return 0;
}
bool aremore(int a, vector &A)
{
int i=A.size()-1;
while(A[i]>a)
{
i–;
}
if(A[i]==a)
{
return 1;
}
return 0;
}
int Solution::perfectPeak(vector &A) {
if(A.size()<3)
{
return 0;
}
for(int i=1;i<A.size()-1;i++)
{
if(areless(A[i],A) && aremore(A[i],A))
{
return 1;
}
}
return 0;
}


#2

This code must be taking more time. As for every element you are checking if it satisfies the condition. In the worst case, it will take O(n^2) time. This can be solved using some extra space in O(n) time.