You are given an array A of length N. An element X is said to be *dominant* if the frequency of X in A is strictly greater than the frequency of any other element in the A.

For example, if A = [2, 1, 4, 4, 4] then 4 is a dominant element since its frequency is higher than the frequency of any other element in A.

Find if there exists any dominant element in A.

------ Input Format ------ 

- The first line of input contains a single integer T — the number of test cases. Then the test cases follow.
- The first line of each test case contains an integer N — the size of the array A.
- The second line of each test case contains N space-separated integers A_{1}, A_{2}, \ldots, A_{N} denoting the array A.

------ Output Format ------ 

For each test case, output YES if there exists any dominant element in A. Otherwise, output NO.

You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical).

------ Constraints ------ 

$1 ≤T ≤500$
$1 ≤N ≤1000$
$1 ≤A_{i} ≤N$

----- Sample Input 1 ------ 
4
5
2 2 2 2 2
4
1 2 3 4
4
3 3 2 1
6
1 1 2 2 3 4

----- Sample Output 1 ------ 
YES
NO
YES
NO

----- explanation 1 ------ 
Test case $1$: $2$ is the dominant element.

Test case $2$: There does not exist any dominant element.

Test case $3$: $3$ is the dominant element.

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
for test_cases in range(int(input())):
	length = int(input())
	list_a = list(map(int, input().split()))
	dict_a = dict()
	for i in list_a:
		if i not in dict_a:
			dict_a[i] = 1
		else:
			dict_a[i] += 1
	list_b = sorted(dict_a.values())
	if len(list_b) == 1 or list_b[-1] != list_b[-2]:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	m = input()
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	s = list(d.values())
	if s.count(max(s)) == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = Counter(input().split()).most_common(2)
	print('YES' if len(a) == 1 or a[0][1] > a[1][1] else 'NO')


for i in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	count = [0] * 1001
	for i in range(len(nums)):
		count[nums[i]] += 1
	maxi = max(count)
	if count.count(maxi) == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	c = Counter(x).values()
	ans = []
	for i in c:
		ans.append(i)
	m1 = max(ans)
	z = ans.count(m1)
	if z == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	c = Counter(arr)
	valList = list(c.values())
	valList.sort(reverse=True)
	if len(valList) == 1:
		print('YES')
	elif valList[0] == valList[1]:
		print('NO')
	else:
		print('YES')
	t -= 1


from statistics import multimode
for i in range(int(input())):
	N = int(input())
	l = list(map(int, input().split()))
	L = multimode(l)
	if len(L) > 1:
		print('NO')
	else:
		print('YES')


def fun(l):
	z = [0] * 1001
	for i in l:
		z[i] += 1
	m = max(z)
	c = 0
	for i in z:
		if i == m:
			c = c + 1
			if c > 1:
				return 'NO'
	return 'YES'
t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	print(fun(l))


from statistics import multimode
goals = int(input())
for distractions in range(goals):
	wife = int(input())
	life = list(map(int, input().split()))
	aim = multimode(life)
	if len(aim) > 1:
		print('NO')
	else:
		print('YES')


from collections import Counter
n = int(input())
for i in range(n):
	k = input()
	s = Counter(input().split()).most_common(2)
	print('YES' if len(s) == 1 or s[0][1] > s[1][1] else 'NO')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	max1 = max(d.values())
	p = 0
	for key in d:
		if d[key] == max1:
			p += 1
	if p > 1:
		print('NO')
	elif p == 1:
		print('YES')


n = int(input())
for i in range(n):
	x = int(input())
	a = list(map(int, input().split()))
	fc = [0] * (max(a) + 1)
	m = 0
	r = 0
	k = 0
	for i in range(len(a)):
		fc[a[i]] += 1
	for i in range(len(fc)):
		if fc[i] > m:
			m = fc[i]
			k = i
	for i in range(len(fc)):
		if i != k:
			if fc[i] > r:
				r = fc[i]
	if m == r:
		print('NO')
	elif m == 1 and r == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	n = int(input())
	x = list(map(int, input().split()))
	freq = {}
	for i in x:
		freq[i] = freq.get(i, 0) + 1
	dominant_element = max(freq, key=freq.get)
	for (k, v) in freq.items():
		if k != dominant_element and v >= freq[dominant_element]:
			print('NO')
			break
	else:
		print('YES')


from collections import Counter
b = int(input())
while b > 0:
	n = int(input())
	a = Counter(input().split()).most_common(2)
	print('YES' if len(a) == 1 or a[0][1] > a[1][1] else 'NO')
	b = b - 1


t = int(input())
for i in range(0, t):
	n = int(input())
	s = list(map(int, input().split()))
	f = [0] * (max(s) + 1)
	for k in s:
		f[k] = f[k] + 1
	c = 0
	m = max(f)
	for l in f:
		if m == l:
			c = c + 1
			if c == 2:
				break
	if c == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter
for i in range(int(input())):
	l1 = []
	a = (int, input())
	l = list(map(int, input().split()))
	c = Counter(l)
	for i in c.values():
		l1.append(i)
	e = max(l1)
	l1.remove(e)
	for i in l1:
		if i == e:
			print('NO')
			break
	else:
		print('YES')


from collections import Counter
for i in range(0, int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = Counter(a)
	l = []
	for j in d:
		l.append(d[j])
	if l.count(max(l)) > 1:
		print('NO')
	else:
		print('YES')


t = int(input())
while t > 0:
	n = int(input())
	L = map(int, input().split())
	f = [0] * (n + 1)
	m = 0
	c = 0
	for i in L:
		f[i] = f[i] + 1
		if m < f[i]:
			m = f[i]
	for i in f:
		if i == m:
			c = c + 1
		if c == 2:
			break
	if c == 2:
		print('NO')
	else:
		print('YES')
	t = t - 1


z = int(input())
for i in range(z):
	n = int(input())
	l = list(map(int, input().split()))
	h = {}
	for i in range(len(l)):
		if l[i] not in h:
			h[l[i]] = 1
		else:
			h[l[i]] += 1
	l2 = []
	for (keys, values) in h.items():
		l2.append(values)
	a = max(l2)
	if l2.count(a) > 1:
		print('NO')
	else:
		print('YES')


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	final_list = []
	arr = list(map(int, input().split(' ')))
	occurence_count = Counter(arr)
	final_list.append(occurence_count.most_common(2))
	for i in final_list:
		if len(i) == 1:
			print('YES')
		elif i[0][1] == i[1][1]:
			print('NO')
		else:
			print('YES')


for i in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	freq_arr = [0] * (N + 1)
	for j in A:
		freq_arr[j] += 1
	max_dominate_value = max(freq_arr)
	if freq_arr.count(max_dominate_value) == 1:
		print('YES')
	else:
		print('NO')


from collections import Counter as cntr
for _____cases_____ in range(int(input())):
	N = int(input())
	A = cntr(input().split()).most_common(2)
	print('YES' if len(A) == 1 or A[0][1] > A[1][1] else 'NO')


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	lst = [0] * (n + 1)
	for i in a:
		lst[i] += 1
	x = max(lst)
	if lst.count(x) == 1:
		print('YES')
	else:
		print('NO')


s = int(input())
for i in range(s):
	n = int(input())
	s1 = list(map(int, input().split()))
	d = {}
	for i in s1:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	k = list(d.values())
	if k.count(max(k)) == 1:
		print('YES')
	else:
		print('NO')


c = int(input())
for i in range(c):
	n = int(input())
	s = list(map(int, input().split()))
	d = {}
	for i in s:
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
	a = max(d.values())
	m = a
	l = 0
	k = d.items()
	for (ia, j) in k:
		if j == m:
			l += 1
	if l == 1:
		print('YES')
	else:
		print('NO')


T = int(input())
for i in range(T):
	l = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	lst = list(d.values())
	if lst.count(max(lst)) == 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	a = max(d.values())
	lst = list(d.values())
	print('YES' if lst.count(a) == 1 else 'NO')


T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	c = 0
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	f = 0
	for i in d:
		if d[i] > f:
			f = d[i]
			j = i
	for i in d:
		if d[i] == f:
			c = c + 1
	if c == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	l = [0] * (n + 1)
	for i in li:
		l[i] += 1
	p = max(l)
	if l.count(p) == 1:
		print('YES')
	else:
		print('NO')


s = int(input())
for i in range(s):
	m = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
	x = max(d.values())
	m = d.items()
	ans = 0
	cnt = 0
	for (i, j) in m:
		if j == x:
			ans = i
			cnt += 1
	if cnt == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	k = list(d.values())
	if k.count(max(k)) == 1:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	d = {}
	for i in lst:
		if i not in d.keys():
			d[i] = 1
		else:
			d[i] += 1
	h = list(d.values())
	if h.count(max(h)) == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	h = {}
	for i in l:
		if i not in h:
			h[i] = 1
		else:
			h[i] += 1
	l2 = []
	for (keys, values) in h.items():
		l2.append(values)
	b = max(h.values())
	if l2.count(b) == 1:
		print('YES')
	else:
		print('NO')


s = int(input())
for i in range(s):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	k = max(d.values())
	c = 0
	for v in d.values():
		if v == k:
			c += 1
	if c == 1:
		print('YES')
	else:
		print('NO')


import collections
t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = collections.Counter(l)
	c = list(d.values())
	if c.count(max(c)) == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	k = max(d.values())
	l1 = []
	for i in d.values():
		l1.append(i)
	if l1.count(k) == 1:
		print('YES')
	else:
		print('NO')