why my RAINBOWA solution is wrong ?

#include
using namespace std;

int main() {
int t,i,j,n,a[100],b[100],k=0;
cin>>t;
while(t--)
{
    cin>>n;
    for(i=0,j=n-1;i<n;i++,j--)
    {
        cin>>a[i];
        if(a[i]>7)
        {
            break;
        }
        b[j]=a[i];
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==b[i])
        {
            k=1;
        }else
        {
            k=0;
            break;
        }
        
    }
    if(k==0)
    {
        cout<<"no"<<endl;
    }else
    {
        cout<<"yes"<<endl;
    }
}
	return 0;
}
And I want to know Why this One is correct ?

 #include<stdio.h>
    main()
    {
    	int t,i;
    	scanf("%d",&t);
    	while(t--)
    	{
    		int n,c=0;
    		scanf("%d",&n);
    		int a[n];
    		for(i=0;i<n;i++)
    		scanf("%d",&a[i]);
    		for(i=0;i<n/2;i++)
    		{
    			if(a[i]==a[n-i-1])
    			c++;
    		}
    		if(c==n/2 && a[n/2]==7)
    		printf("yes\n");
    		else
    		printf("no\n");
    	}
    }   

Please Reply ASAP
Thank you
for(i=0,j=n-1;i<n;i++,j--)
    {
        cin>>a[i];
        if(a[i]>7)
        {
            break;
        }
        b[j]=a[i];
    }

You arent even taking the complete input. Atleast take the array as input , else those valeus will be taken as next N and will mess up the process.

1 Like

can you tell me where is my code wrong??

https://www.codechef.com/viewsolution/16583705

@vijju123 @berezin

Please tend to ask this as a new question, I missed your comments!!

Here is the TC-

Input
1
14
1 2 3 3 3 3 3 3 3 3 3 3 2 1
Your Output
yes
Correct Output
no
Error: Not checking for 7 as max element.

@vijju123 actually I don’t have the required reputation points…

sorry that I had to ask like that…

I made a thread where you people can ask questions and I convert/upgrade them to individual threads.