Getting a NZEC even though it is running fine on my pc, please help!
Problem link
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class VOTERS {
public static void updateList(ArrayList<Integer> finallist, int id) {
for(int i = 0; i < finallist.size(); i++) {
if(id == finallist.get(i)) {
return;
}
}
finallist.add(id);
}
public static void main(String args[])
throws IOException {
Scanner in = new Scanner(System.in);
int N = 3;
int n[] = new int[N];
n[0] = in.nextInt();
n[1] = in.nextInt();
n[2] = in.nextInt();
ArrayList<Integer> finallist = new ArrayList<Integer>();
int voters[][] = new int[N][50000];
for(int i = 0; i < N; i++) {
for(int j = 0; j < n[i]; j++) {
voters[i][j] = in.nextInt();
}
}
for(int i = 0; i < n[0]; i++) {
int temp = voters[0][i];
for(int j = 0; j < n[1] || temp <= voters[1][j]; j++) {
if(temp == voters[1][j]) {
updateList(finallist, temp);
}
}
temp = voters[1][i];
for(int j = 0; j < n[2] || temp <= voters[2][j]; j++) {
if(temp == voters[2][j]) {
updateList(finallist, temp);
}
}
temp = voters[2][i];
for(int j = 0; j < n[0] || temp <= voters[0][j]; j++) {
if(temp == voters[0][j]) {
updateList(finallist, temp);
}
}
}
Collections.sort(finallist);
System.out.println(finallist.size());
for(int i = 0; i < finallist.size(); i++) {
System.out.println(finallist.get(i) + " ");
}
in.close();
}
}