why my soln to rainbowa giving wrong ans???

import java.util.Scanner;

public class Main {

public static void main(String[] args)throws java.lang.Exception {
	// TODO Auto-generated method stub
	Scanner s = new Scanner(System.in);
	int t = s.nextInt();

	while (t>0) {
		boolean array=false;
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		for (int i = 0; i < n / 2; i++) {
			if (a[i] == a[n - i-1] && (a[i + 1] == a[i] + 1 || a[i + 1] == a[i])) {
			 array=true;

			} else {
				 array=false;
			}

		}
		System.out.println(array);

		t--;
	}

}
}

You should be printing either “yes” or “no” instead of true and false.

And make sure you understand what’s a good rainbow array is

Here

1

11

1 2 4 5 6 7 6 5 4 2 1

The above test case’s array is not a good rainbow array because it increases by more than 1
look at the difference between second and third element is more than 1.

4-2 ==> 2

1

5

1 2 3 2 1

This is also not a good rainbow array because it doesn’t go till 7

Hope this helps!!

1 Like

i have rectified my mistake of printing true/false intead of yes/no. but it still says wrong ans.why???

Where are you checking if arr[i] is in range of [1,7]? Just checking palindromity wont help.

your code doesn’t work for the above test cases I provided, take a look at them and make conditions according to the test cases!! You do not have a complete logic right now, try adding few conditions and it will work

Take a look at my solution https://www.codechef.com/viewsolution/14840003