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
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