why my RAINBOWA solution giving Wrong answer ????

this solution is giving WA . I want to know on which test case it is failing ?
Best Regards

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

int main() {
	ios::sync_with_stdio(false);
	
	ifstream fin;
	fin.open("test.txt");
	int t ;
	fin >> t;
	
	while( t-- )
	{
		ll n;
		fin >> n;
		int arr[n];
		for( int i=0; i<n; i++)
		{
			fin >> arr[i];
		}
		int len = n/2;
	//	cout << arr[len] << "before\n";
		int index = n-1,check= arr[(n/2) - 1] + 1;
		bool b = false;
		for( int j=0; j<n/2; j++)
		{
			if( arr[j] != arr[index--])
			{
				b = true;
				break;
			}
		}
	//	cout << arr[len] << "  " << check << endl;
		if( b == true )
		{
			cout << "no\n";
		}
		else if( b == false )
		{
			  
			 if( arr[len] != check )
			{
				cout << "no\n";
			} 
			else if ( arr[0] != 1 || arr[n-1] != 1)
			{
				cout << "no\n";	
			}
			else
				cout << "yes\n";
		}
	}
	
	return 0;
}

Your code fails here-

Input
1
14
1 2 3 4 5 6 7 7 6 5 4 3 2 1
Your output
no
Correct Output
yes

We can have any number of 7 in rainbow array.

The only two condition you need is to check is whether the number is palindrome or not(if not print -1) and the second condition is that it should contain 7 as its mid element(Your array can have more than one 7 in it).
You can view my solution for further queries - CodeChef: Practical coding for everyone

Is this the code you have submitted?

1 Like

yes @sun_d

thanks for quick response . in the problem it says
First a1 elements equal 1.
Next a2 elements equal 2.
Next a3 elements equal 3.
Next a4 elements equal 4.
Next a5 elements equal 5.
Next a6 elements equal 6.
Next a7 elements equal 7.
Next a6 elements equal 6.
Next a5 elements equal 5.
Next a4 elements equal 4.
Next a3 elements equal 3.
Next a2 elements equal 2.
Next a1 elements equal 1

then in constraints it says
1 >= Ai <= 10
if array goes to 7 then why 10 in constraints ???

thanks for quick response @devagarwal

It means that every element of array is less than 10, size of array can be as large as 50. We can prove that there is no rainbow array of size<=10, you need atleast 13 elements