-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandies.java
More file actions
37 lines (32 loc) · 752 Bytes
/
Candies.java
File metadata and controls
37 lines (32 loc) · 752 Bytes
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
32
33
34
35
36
37
import java.util.*;
import java.lang.*;
import java.io.*;
class Candies {
public static void main(String[] args) throws java.lang.Exception {
// your code goes here
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T-- > 0) {
int N = sc.nextInt();
int arr[] = new int[2 * N];
for (int i = 0; i < 2 * N; i++) {
arr[i] = sc.nextInt();
}
Map<Integer, Integer> map = new HashMap<>();
int count = 0;
for (int num : arr) {
map.put(num, map.getOrDefault(num, 0) + 1);
}
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (entry.getValue() >= 3) {
count++;
}
}
if (count > 0) {
System.out.println("NO");
} else {
System.out.println("YES");
}
}
}
}