Introduction
Finding the minimum length unsorted subarray is grounded on the Sorting algorithm. We have to find the minimum length of unsorted subarray for which the complete array gets sorted.
What do you mean by subarray?
A subarray is a contiguous part of an array. For example arr=[1,2,3], the subarrays are (1),(2),(3),(1,2),(2,3),(1,2,3).
Now let’s understand the problem statement.
Also read, Euclid GCD Algorithm
Problem Statement
We are given an Array. We need to find an unsorted subarray of minimum length such that if we sort that unsorted subarray, the complete array gets sorted. We need to output (s, e) where s is the starting index of the unsorted subarray and e is the ending index of the unsorted array.
Let us see a few examples:-
Input:
arr: [1, 2, 3, 9, 7, 8, 6, 10]
Output:
3 6
Explanation:
If we sort the subarray (3, 6), we will get the following array:-
[1, 2, 3, 6, 7, 8, 9, 10].