out of 10 test cases 6 are correct while the remaining are wrong. I am not able to identify where my code has got wrong as the code is working on my custom inputs. please help!
the code is given below-
#include
using namespace std;
int main() {
int n,i,j;
int flag=0;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(a[i]>a[j])
{
if(a[j]<a[j+1])
{
flag=1;
break;
}
}
else if(a[i]<a[j])
{
if(a[j]>a[j+1])
{
flag=1;
break;
}
}
}
if(flag==1)
break;
}
if(flag==1)
{
cout<<“false”;
}
else
{
cout<<"true";
}
return 0;
}