You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. Given an array and its length, return 1 if its possible if its possible to split the array at any index such that all the elements in the left half are strictly decreasing and all elements in right half are strictly increasing
#include<iostream>usingnamespacestd;intisSplitPossible(int arr[], int len) {
bool increased = false;
prev = arr[0];
for(int i = 0; i < len; i++) {
if (arr[i] == prev)
return0;
elseif (!increased && arr[i] > prev) {
increased = true;
}
elseif (arr[i] < prev) {
return0;
}
prev = arr[i];
}
return1;
}
intmain() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
cout << isSplitPossible(arr, n) << endl;
return0;
}
2. Remove Consecutive Duplicate elements recursively