Easiest c++ sol. O(n) time and O(1) space


#1

vector Solution::subUnsort(vector& A){
vector ans;
int leftmax=0, rightmin=A.size()-1, start=A.size()-1, end=0;

for(int i=0; i<A.size(); i++){
    if(A[i] >= A[leftmax])
        leftmax = i;
    else
        end = i;
        
    if(A[A.size()-i-1] <= A[rightmin])
        rightmin = A.size()-i-1;
    else
        start = A.size()-i-1;
}

if(end == 0)
    ans.push_back(-1);
else{
    ans.push_back(start);
    ans.push_back(end);
}

return ans;

}