Why is my rainbow array code giving wrong answer after submission

#include
using namespace std;
int main()
{
bool flag=false;
int N,i,t=0;
cin>>t;
while(t–)
{
cin>>N;
int a[N];
for(i=0;i<N;i++)
{
cin>>a[i];
}
for(i=0;i<N/2;i++)
{
if(a[i]-a[i+1] < 1 && a[N/2]==7 && a[i]==a[N-i-1])
{
flag=true;
}
else
{
flag=false;
break;
}
}
if(flag)
cout<<“yes”;
else
cout<<“no”;
}
return 0;
}

You are not checking that the numbers in rainbow array are in range of [1,7] only. You ought to search forums for previous such questions, it is a very common error done by people.

1 Like

Make sure that your code compiles before you ask questions. Otherwise you will not get any answers.

People don’t even use the search bar!! lmao

1 Like