My issue
I’m printing the right values and my code compiles and runs correctly, but it doesn’t give the correct answer when I hit submit.
My code
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.HashMap;
import java.util.Collections;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scnr = new Scanner(System.in);
int T = scnr.nextInt();
int N = scnr.nextInt();
ArrayList<Integer> arr = new ArrayList<Integer>();
HashMap<Integer, Integer> hash = new HashMap<Integer, Integer>();
for (int i = 0; i<N; i++) {
arr.add(scnr.nextInt());
}
for (Integer item : arr) {
if (!hash.containsKey(item)) {
hash.put(item, 1);
} else {
hash.put(item, hash.get(item)+1);
}
}
for (Integer elem : hash.keySet()) {
if (hash.get(elem) == 1) {
System.out.println(elem);
}
}
scnr.close();
}
}
Problem Link: MISSP Problem - CodeChef