Fastest C++ solution using continue and goto statements


#1

Code to pass all test cases
vectorresult;
for(int i=0;i<A.size()-1;i++){
for(int j=i+1;j<A.size();j++){
if(A[i] < A[j])
goto here;
}
result.emplace_back(A[i]);
here:
continue;
}
result.emplace_back(A[A.size()-1]);
return result;


#2

Its always preferable to avoid goto. My solution of o(n)

vector Solution::solve(vector &A) {
vector B;

int max=A[A.size()-1];

B.push_back(max);
for(int i=A.size()-2; i>=0 ;--i)
{
    if(max<A[i])
    {
        B.push_back(A[i]);
        max=A[i];
    }
}

return B;

}