Why partially correct (memory limit exceeded)


#1

bool left(vector A, int i, int k)
{
if(i==0) return true;
if(A[i-1]>k) return false;
else return left(A,i-1,k);
}
bool right(vector A, int n, int i, int k)
{
if(i==n-1) return true;
if(A[i+1]<k) return false;
else return right(A,n,i+1,k);
}
int Solution::perfectPeak(vector &A) {
int n=A.size();
int f=0;
for(int i=1; i<n-1; i++)
{
if(right(A,n,i, A[i]) && left(A,i, A[i])){
return 1; break;
}
}
return 0;
}


#2

try with passing vector as pass by reference