Minimum Sub Array to Sort
Q91: Given an unsorted array of specific size. Write a program in C to find the minimum length of subarray such that, sorting this subarray makes the whole array sorted.
10 12 15 17 28 32 42 18 56 59 67
The minimum length of unsorted subarray which makes the given array sorted
lies between the index 4 and 7
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int li=n,ri=0;
for(int i=0;i<n-1;i++){
if(arr[i]>arr[i+1]){
cout<<"Get disorder "<<i+1<<endl;
ri=i+1;
int lli=0;
for(int j=i-1;j>=0;j--){
if(arr[j]<arr[ri]){
cout<<"\t less get "<<arr[j]<<' '<<arr[ri]<<endl;
lli=j+1;
break;
}else{
cout<<"\t not les "<<arr[j]<<' '<<arr[ri]<<endl;
}
}if(lli<li) li=lli;
}else{
cout<<"ordered : "<<arr[i]<<' '<<arr[i+1]<<endl;
}
}cout<<li<<' '<<ri<<endl;
}
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন