Why my code is wrong ?

link - https://www.codechef.com/status/TEMPLELA,soham213

#include <iostream>
using namespace std;
 
int main() {
	 int flag1=1; int flag2 =1;int k=1;int t;
	 cin>>t;
	 while(t>0)
	{
	int c;
	cin>>c;
	int ar[c];
	for(int l=0;l<c;l++)
	{
	    cin>>ar[l];
	}
	for(int i=0;i<c/2 + 1 ;i++)
	{
	    if(ar[i]!=i+1)
	    {
	        flag1=0;
	        break;
	    }
	}
	for(int j=c-1;j>c/2 ; j--)
	{
	    if(ar[j]!=k)
	    {
	         flag2=0;
	         break;
	    }
	    k++;
	    
	}
	if(ar[c/2 -1]!=ar[c/2 ]-1)
	flag1 =0;
	
	if(flag1 && flag2)
	cout<<"yes";
	else
	cout<<"no";
	--t;
	}
	return 0;
}
cout<<"yes";
	else
	cout<<"no";

Print each answer on a new line? :stuck_out_tongue:

This is one of the nightmares that newbies face.

1 Like

You may have a look at simple solution approach here.

I have used the same idea, but much less code, only one for loop…

Hope it would be instructive…

Please Upvote if you find this helpful…