Giving Wrong Answer in Chef and Rainbow Array?

I have been trying to solve the Rainbow array problem, I wrote a code in Java, I think it’s correct but the compiler is giving wrong answer, can someone please help in finding out the error…

here is the code

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner obj = new Scanner(System.in);
		int n = obj.nextInt();
		while (n--  > 0) {
			int a=0,b=0,c=0,d=0,e=0,f=0,g=0;
			List<Integer> numberList = new ArrayList<Integer>();
			int counter =  obj.nextInt();int total = counter;;
			while(counter>0){
			int curr = obj.nextInt();
			numberList.add(curr);
			counter--;
			}
			Iterator<Integer> iter = numberList.iterator();
			while (iter.hasNext()) {
				int num = iter.next();
                if(num==1)
                    a+=1;
                else if(num==2)
                    b+=1;
                else if(num==3)
                    c+=1;
                else if(num==4)
                    d+=1;
                else if(num==5)
                    e+=1;
                else if(num==6)
                    f+=1;
                else if(num==7)
                    g+=1;
				}
			if(a!=0&&b!=0&&c!=0&&d!=0&&e!=0&&f!=0&&g!=0){
					if(a+b+c+d+e+f+g==total){
						System.out.println("yes");
						continue;}

		}
			System.out.println("no");

		}
		obj.close();
	}
}

alright so most of your code is correct, although code can be shortened, the main problem with your program is that after checking that numbers till 1 to 7 exists in the array, you should also check that the numbers from 1 to 6 are even in the given array, this will be the case as

if there is 1 one in the array then for it to be a rainbow array there should be a total of 2 ones

if there are 2 ones in the array then for it to be a rainbow array there should be a total of 4 one’s

so after your

if(a!=0&&b!=0&&c!=0&&d!=0&&e!=0&&f!=0&&g!=0)

condition
you should also check for this condition

if(a%2==0&&b%2==0&&c%2==0&&d%2==0&&e%2==0&&f%2==0)

hope this helps. Keep coding

bro…I think your code doesn’t bother about the order of numbers…where to get the correct answer you must check for the order of appearance of numbers…they must be strictly in increasing order at first and the they must decrease in the reverse order.
Hope it helps!!!

2 3 1 4 5 6 7 6 5 4 1 3 2

is this rainbow array or not??

alright, I was able to successfully submit my code, thanks a lot!

your welcome! :slight_smile: