Is this an O(N) solution?


#1

vector Solution::subUnsort(vector &A) {
vectorresult;
vector B = A;
sort(B.begin(), B.end());
int len = A.size();
int i = 0;
while (i < len and A[i] == B[i]) i++;
int j = len - 1;
while (0 <= j and A[j] == B[j]) j–;
if (i <= j) {
result.push_back(i);
result.push_back(j);
}
else {
result.push_back(-1);
}
return result;
}


#2

No, it is O(nlogn) + O(n) ~ O(nlogn)