0% found this document useful (0 votes)
29 views2 pages

Java InputTakingPart

Uploaded by

HARSHIT TRIPATHI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Java InputTakingPart

Uploaded by

HARSHIT TRIPATHI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*;
import java.util.*;
import java.lang.*;
import java.util.stream.*;
import static java.util.stream.Collectors.toList;

public class Main {

public static void subset(List<Integer> arr,int n) {

// System.out.println(arr);

Map<Integer,Integer> hashMap=new HashMap<Integer,Integer>();

for(Integer s:arr){

hashMap.put(s,hashMap.getOrDefault(s,0)+1);
}

for (Map.Entry<Integer,Integer> entry : hashMap.entrySet()){

// System.out.println("Key = " + entry.getKey() +


// ", Value = " + entry.getValue());

if(entry.getValue()==1){
System.out.println(entry.getKey());
}
}

public static void main(String[] args) throws IOException {

BufferedReader bufferedReader = new BufferedReader(new


InputStreamReader(System.in));

try {

int tr = Integer.parseInt(bufferedReader.readLine().trim());

for(int i=0; i<tr; i++){


int n = Integer.parseInt(bufferedReader.readLine().trim());
List<Integer> arr =
Stream.of(bufferedReader.readLine().trim().split(" "))
.map(Integer::parseInt)
.collect(Collectors.toList());

subset(arr,n);
}

} catch (IOException ex) {


throw new RuntimeException(ex);
}

bufferedReader.close();
}

You might also like