Easy and fast C++ solution


#1

`vector Solution::solve(vector &arr) {
vector res;
res.push_back(arr[arr.size()-1]);
for(int i=arr.size()-2;i>=0;i–)
{
if(arr[i]>res.back())
res.push_back(arr[i]);
}

return res;

}
`


#2

nice it worked. I used the nested for loop the code was correct but the output has been shown wrong.I think the problem was the time complexity. I just modified my code with reference with your’s.