Simplest solution in O(nLogn)


#1

.vector<int> Solution::subUnsort(vector<int> &A) { vector<int>B=A; sort(B.begin(),B.end()); if (B==A){ return vector<int>{-1}; } int start=0; bool sfound=false; int end=0; for(int i=0;i<A.size();i++){ if(A[i]!=B[i]){ if(!sfound){ start=i; sfound=true; } end=i; } } return vector<int>{start,end}; }


#2

Best solution is O(n) time and O(1) space


#3

Space is not O(1) but is rather O(n)