-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveSmallest.java
More file actions
35 lines (31 loc) · 867 Bytes
/
RemoveSmallest.java
File metadata and controls
35 lines (31 loc) · 867 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
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
public class RemoveSmallest {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
List<Integer> l = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
l.add(sc.nextInt());
}
System.out.println(solve(l, l.size()));
}
}
private static String solve(List<Integer> l, int size) {
// TODO Auto-generated method stub
PriorityQueue<Integer> q = new PriorityQueue<Integer>((a, b) -> {return b - a;});
q.addAll(l);
while (q.size() > 1) {
int x = q.poll();
int y = q.poll();
if (Math.abs(x - y) > 1) return "NO";
q.add(y);
}
return "YES";
}
}