Simple C++ Recursive solution using STL algorithms

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];
        //no right ST found
        return find(A, s+1, e);
        //right st found, validate right ST and recurse
        int r1 = distance(
            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);