couldn’t pass test case 2 and 3 although things are working fine in compiler. my code is
#include
using namespace std;
bool issorted_ascending(long int arr[],int n){
if(n==1)
return true;
if(arr[0]<arr[1] and issorted_ascending(arr+1, n-1))
return true;
else
return false;
}
bool issorted_descending(long int arr[],int n){
if(n==1)
return true;
if(arr[0]>arr[1] and issorted_descending(arr+1, n-1))
return true;
else
return false;
}
int main() {
int n;
cin>>n;
long int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
if(issorted_ascending(arr,n)|| issorted_descending(arr,n))
cout<<“true”;
else
cout<<“false”;
return 0;
}