#Given an unsorted array,find the minimum length of subarraay,sorting which sorts the whole array. #Time-complexity: O(n),Auxiliary-space:O(1) =begin Algorithm: Scan left to right and find first index where next element is less than current,let it be l (if l==a.length-1 it is already sorted),similarly scan right to left and search first index where previous element is larger than current,let it be r.Now search for min and max in l to r, now from 0 to l-1 find first element which is greater than min(let it be i) and from r+1 to a.length-1 find first element which is less than max.(let it be j) set l= i and r=j minimum length= r-l+1 start=l end=r =end def unsorted_sub(a) n=a.length l=0 r=n-1 for i in 0...n-1 if a[i]>a[i+1] l=i break else l+=1 end end return "The complete array is sorted" if l==n-1 for i in (n-1).downto(1) if a[i]a[min_i] l=i break end end for i in (n-1).downto(r+1) if a[i]a[max] max=i elsif a[i] Length: 5, Starting index: 3, Ending index: 7 unsorted_sub([1,2,3,4,5,6]) # => The complete array is sorted