Getting wrong ans in test case 2

#include
#include<bits/stdc++.h>
using namespace std;

bool sorted(int *ar,int n)
{
if(n==1)
return true;
if(ar[0]<ar[1] && sorted(ar+1,n-1))
return true;
return false;
}

int main() {
int n;
cin>>n;
int ar[n];
for(int i=0;i<n;i++)
cin>>ar[i];
if(sorted(ar,n))
cout<<“true”;
else
cout<<“false”;
return 0;
}

Hey @firozbhaikardar21
It’s better to pass current index i, and compare I and i+1 instead of 0 and 1 and pass the arr like int arr[] in the function.

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.