The Simplest C++ Solution in O(n)!

flipkart
programming
interview-questions
Tags: #<Tag:0x00007f18203fa068> #<Tag:0x00007f18203f9f28> #<Tag:0x00007f18203f9de8>

#1

int Solution::perfectPeak(vector &A) {

int max = A[0];
int min;
for(int i=1;i<A.size()-1;i++){
    if(A[i]>max){
        max = A[i];
        min = *min_element(A.begin()+i+1, A.end());
        if(max<min){
            return 1;
        }
    }
    
}
return 0;

}