Simple C++ Recursive solution using STL algorithms


#1
int find(vector<int> & A, int s, int e){
    if(e>=s) return 1;
    int r = distance(A.begin(), 
            find_if(begin(A)+s, begin(A)+e+1, [&](int i){
               return i >  A[s];
            })
        );
        
    if(r>e){
        //no right ST found
        return find(A, s+1, e);
    }else{
        //right st found, validate right ST and recurse
        int r1 = distance(
            A.begin(), 
            find_if(begin(A)+r, begin(A)+e+1, [&](int i){
               return i <  A[s];
            })
        );
        if(r1!=e+1) return false;
        return find(A, s+1, r-1) and find(A, r, e);
    }
}
int Solution::solve(vector<int> &A) {
    return find(A, 0, A.size()-1);
}```