-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathFrequencyGame.java
31 lines (29 loc) · 1.01 KB
/
FrequencyGame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class FrequencyGame {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n =sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i < n; i++)
arr[i] = sc.nextInt();
Map<Integer,Integer> map = new HashMap<>();
for(int i = 0; i < n; i++){
map.put(arr[i], map.getOrDefault(arr[i], 0)+1);
}
System.out.println(map);
int min = Integer.MAX_VALUE;
int ans = Integer.MIN_VALUE;
for (Map.Entry<Integer,Integer> ele : map.entrySet()) {
if(ele.getValue()<=min){
min = ele.getValue();
ans = Math.max(ans,ele.getKey());
}
}
System.out.println(ans);
}
}
}