Simple CPP O(n) solution


#1

vector Solution::solve(vector &A) {

vector<int> v;
int max_so_far=INT_MIN;
for(int i=A.size()-1;i>=0;i--)
{
    if(A[i] > max_so_far) v.push_back(A[i]);
    max_so_far = max(max_so_far,A[i]);
}
return v;

}