Why is this not giving correct output?


#1

int Solution::perfectPeak(vector &A) {
int n = A.size();
int l = 0;
int r = n-1;
for(int i=1;i<n-1;i++){
while(l<i){
if(A[l]<A[i])
l++;
else{
l=0;
break;
}
}
while(r>i){
if(A[r]>A[i])
r–;
else{
r=n-1;
break;
}
}
if(l!=0 && r!=(n-1))
return 1;
}
return 0;
}