A Simple stack based solution


#1
int Solution::solve(vector<int> &A) {
    stack<int>st;
    int root = INT_MIN;
    for(int i=0;i<A.size();i++)
    {
        if(A[i]<root)
        return 0;
        while(st.size() and st.top()<A[i])
        {root =st.top(); st.pop();
        }
        st.push(A[i]);
        
    }
    return 1;
}