Repository navigation
Expand file tree
/
Copy pathDoremysPaint3.java
More file actions
56 lines (55 loc) · 1.52 KB
/
Copy pathDoremysPaint3.java
File metadata and controls
56 lines (55 loc) · 1.52 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.HashMap;
import java.util.Scanner;
public class DoremysPaint3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t--!=0)
{
int n=sc.nextInt();
HashMap<Integer,Integer>mp=new HashMap<>();
for(int i=0;i<n;i++)
{
int a=sc.nextInt();
mp.put(a,mp.getOrDefault(a,0)+1);
}
if(mp.size()>=3)
{
System.out.println("NO");
}
else
{
if(mp.size()==1)
{
System.out.println("YES");
}
else
{
int fist=0,sec=0;
boolean found=true;
for(int el:mp.keySet())
{
if(found)
{
found=false;
fist=mp.get(el);
}
else
{
sec=mp.get(el);
break;
}
}
if(Math.abs(fist-sec)<=1)
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}
}
}
}
}
}