Given an array S of size N , check if it is possible to split sequence into two sequences - s1 to si and si to sN such that first sequence is strictly decreasing and second is strictly increasing. Print true/false as output

void checker(int arr[],int n){
int c = 0;
for(int i =0;i<n;i++){
if(arr[i]==(arr[i+1]+1)||arr[i]==(arr[i+1]-1)||(arr[i]+1)==(arr[i+1])||(arr[i]-1)==(arr[i+1])){
c++;
}
}
if(c==(n-1)){
cout<<“true”;
return;
}
else{
cout<<“false”;
return;
}
}

int main(){
int arr[100];
int n;
cin>>n;

for(int i=0;i<n;i++){
    cin>>arr[i];
}

checker(arr,n);

}

hi @gunjit27_94aa0450736b408e
, the question says that you need to check if the the whole array can be partitioned somewhere such that initial numbers are increasing and remaining are decreasing

eg 1 2 3 4 9 8 7 6 can be divided into 1 2 3 4 5 9 (increasing) and 8 7 6 (decreasing)

for implementation difficulties check this I’ve commented properly https://ide.codingblocks.com/s/656052

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.