Failing for larger test cases. Can anyone suggest?


#1

public class Solution {
public int perfectPeak(int[] A) {
if(A.length<3){
return 0;
}
int largest = A[0];
boolean found = true;
for(int i = 1;i<A.length-1;i++){
if(A[i]>largest && A[i]>A[i-1] && A[i]<A[i+1]){
largest = A[i];
int j = A.length-1;
while(j>=i+1){
if(A[j]<A[i]){
found = false;

                    break;
                
                }
                j--;
            }
            if(found){
                return 1;
            }
            found = true;
            i++;

        }
    }
    return 0;
}

}