Dominant Element Solutions
Join My Whatsapp Group
import java.util.*;
class Codechef
{
public static void main (String[] args) throws java.lang.Exception{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] ASD = new int[n];
for(int i=0;i<n;i++){
ASD[i] = sc.nextInt();
}
Map<Integer,Integer> AS = new HashMap<>();
for(int x: ASD){
AS.put(x, AS.getOrDefault(x,0)+1);
}
ArrayList<int[]> l = new ArrayList<>();
for(int k : AS.keySet()){
int v = AS.get(k);
l.add(new int[]{k,v});
}
Collections.sort(l, (o1,o2)->o2[1]-o1[1]);
if(l.size()==1 || l.get(0)[1] > l.get(1)[1]){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
}

Comments
Post a Comment