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();
}
}