find-mode

Write a program to find the mode of a given list of integers. Mode of a number is defined as the number which is most frequently occured. 
For example: 
L = {1,2,2,3} // Here mode is 2(most frequently occured)  

It is possible that multiple answers are possible for a list. In that case print all possible answers in non-increasing order.

Input:
First Line of input contains an integer t represeting the number of test cases, Where first line of each test case has an integers N - number of integers in list, Next line contains N integers.

Output:
print all the possible modes in non-increasing order.

Constraints:
1 ≤ t ≤ 100
1 ≤ N<100000
1 ≤ a[i] ≤ 1000000

SAMPLE INPUT
2
5
1 2 2 2 2 
6
1 2 2 3 3 4

SAMPLE OUTPUT
2 
3 2

Source: hackerearth | Difficulty: EASY
Tags: Fundamentals


Solutions:
_ = eval(input())

while _:
	_ -= 1
	
	eval(input())
	nums = list(map(int, input().split()))
	di = {}
	for i in nums:
		di[i] = di.get(i, 0) + 1
	k = list(di.keys())
	v = list(di.values())
	m = max(v)
	s = v.index(m)
	li = []
	while True:
		li.append(k[s])
		try:
			s = v.index(m, s+1)
		except:
			break
	for i in sorted(li, reverse=True):
		print(i, end=' ')
	print('')
	


from collections import Counter

t = eval(input())
for _ in range(t):
	n = eval(input())
	num_count = Counter(list(map(int, input().strip().split())))
	temp = num_count.most_common(1)
	#print temp
	mode = list()
	max_count = temp[0][1]
	for k, v in list(num_count.items()):
		if v == max_count:
			mode.append(k)
	for val in sorted(mode, reverse=True):
		print(val, end=' ')
	print()


import collections
for i in range(eval(input())):
	k=[]
	j=0
	x=eval(input())
	y=list(map(int,input().split()))
	y=collections.Counter(y).most_common()
	while (y[0][1]==y[j][1]):
            k.append(y[j][0])
            j+=1
        k.sort()
        k.reverse()
        for m in k:
            if j==1:
                print(m)
            else:
                print(m, end=' ')
            j-=1
        
        
   

		

		


import operator

for i in range(eval(input())):
	n = eval(input())
	final = list(map(int,input().split()))
	d = {}
	for i in final:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	t = max(d.values())
	
	f1 = [x for x,y in list(d.items()) if y == t]
	f1.sort(reverse=True)
	
	t = len(f1)
	
	for j in range(t):
		if j == t-1:
			print(f1[j])
		else:
			print(f1[j], end=' ')
			


from collections import Counter


for _ in range(int(input())):
	input()
	c = Counter(input().rstrip().split())
	m = max(c.values())
	res = (k for k, v in list(c.items()) if v == m)
	print((' '.join(sorted(res, reverse=True, key=int))))


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
t=eval(input())

while(t):
	d={}
	l=[]
	n=eval(input())
	x=list(map(int,input().strip().split(" ")))
	for i in x:
		if i not in d:
			d[i]=1
		else:
			d[i]+=1
	m=max(d.values())
	for i in list(d.keys()):
		if d[i]==m:
			l.append(i)
	l=sorted(l,reverse=True)
	print(" ".join(map(str,l)))
	t-=1


t=eval(input())

while(t>0):
	counts=dict()
	n=eval(input())
	inp=input().split()

	for i in range(n):
		counts[int(inp[i])]=counts.get(int(inp[i]),0)+1

	lis=[]
	for n,c in list(counts.items()):
		lis.append((c,n))
	
	lis.sort(reverse=True)

	max=lis[0][0]

	moreWarr=[]
	for c,n in lis:
		if c==max:
			moreWarr.append(n)

	for n in moreWarr:
		print(n, end=' ')
	print('')
	t=t-1
	



for _ in range(eval(input())):
	n=eval(input())
	d={}
	a=list(map(int,input().split()))
	for x in a:
		if x in d:
			d[x]+=1
		else:
			d[x]=1
	maxx=max(d.values())
	a=[x for x,y in list(d.items()) if y==maxx]
	a=sorted(a,reverse=True)
	for x in a:
		print(x, end=' ')
	print()    
		
	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
print 'Hello World!'
'''

import collections
t=int(input())
assert t>=1 and t<=100
for i in range(0,t):
	n=int(input())
	assert n>=1 and n<=100000
	l=input().split()
	d=collections.Counter()
	for x in l:
		d[int(x)]+=1
	l=reversed(sorted(d))
	for r,s in d.most_common(1):
		x=s
	for s in l:
		if d[s]==x:
			print(s, end=' ')
	print()



from collections import defaultdict

test_cases = eval(input())

for _ in range(test_cases):
	count_dict = defaultdict(int)
	_2 = eval(input())
	l = list(map(int, input().split()))
	for el in l:
		count_dict[el] += 1

	highest_val = max(count_dict.values())
	# print highest_val
	result = sorted([_ for _ in count_dict if count_dict[_] == highest_val])
	result.reverse()
	# print result
	print(' '.join([str(_) for _ in result]))


T=int(input())

for _ in range(0,T):
	N=int(input())
	maxCount=0
	countDict={}
	numList=[int(x) for x in input().split()][:N]
	for num in numList:
		countDict[num]=countDict.get(num,0)+1
		if(maxCount<countDict[num]):
			maxCount=countDict[num]
	
	resultList=[]
	
	for k,v in countDict.items():
		if(v==maxCount):
			resultList.append(k)

	print(' '.join(str(x) for x in sorted(resultList,reverse=True)))


test_cases=eval(input())
while test_cases>0:
	num_of_integers=eval(input())
	a=list(map(int,input().split()))
	b=[0]*len(a)	
	mydict=dict(list(zip(a,b)))
	if len(a)==num_of_integers:	
		for i in a:
			mydict[i]+=1			
	else:
		print("wrong input")
		break		
	test_cases=test_cases-1
	highest=max(mydict.values())
	sorted_array=sorted([k for k,v in list(mydict.items()) if v == highest])[::-1]		
	print(' '.join([str(j) for j in sorted_array]))	


from collections import Counter

t = eval(input())
for _ in range(t):
	n = eval(input())
	num_count = Counter(list(map(int, input().strip().split())))
	temp = num_count.most_common(1)
	#print temp
	mode = list()
	max_count = temp[0][1]
	for k, v in list(num_count.items()):
		if v == max_count:
			mode.append(k)
	for val in sorted(mode, reverse=True):
		print(val, end=' ')
	print()


t=eval(input())
l=[]
o=[]
for i in range(0,t):
	n = eval(input())
	L = input()
	l = [int(x) for x in L.split()]
	d={}	
	for j in l:
		if j in d:
			d[j]=d[j]+1
		else:
			d.update({j:1})

	m=0
	mo=[]
	for k,v in d.items():
		if v==m:
			mo.append(k)
		elif v>m:
			del mo[:]			
			mo.append(k)
			m=v
	mo.sort(reverse=True)
	o.append(mo)

for z in o:
	s=''
	for i in z:
		s =s+str(i)+" "
	print(s)
	


test_cases=eval(input())
while test_cases>0:
	num_of_integers=eval(input())
#    li = [0]*1000001	
	a=list(map(int,input().split()))
	b=[0]*len(a)	
	mydict=dict(list(zip(a,b)))
#    print mydict	
	if len(a)==num_of_integers:	
		for i in a:
#            li[i]=li[i]+1
			mydict[i]+=1			
	else:
		print("wrong input")
		break		
	test_cases=test_cases-1
#    highest=max(li)
	highest=max(mydict.values())
	sorted_array=sorted([k for k,v in list(mydict.items()) if v == highest])[::-1]		
	print(' '.join([str(j) for j in sorted_array]))	


if __name__ == '__main__':
	for _ in range(int(input())):
		input()
		m = {}
		entries = list(map(int, input().split()))
		for entry in entries:
			try:
				m[entry] += 1
			except:
				m[entry] = 1
		highest = max(m.values())
		for el in sorted([k for k,v in list(m.items()) if v == highest], reverse = True):
			print(el, end=' ')
		print()


from collections import Counter
 
 
for _ in range(int(input())):
	input()
	c = Counter(input().rstrip().split())
	m = max(c.values())
	res = (k for k, v in list(c.items()) if v == m)
	print((' '.join(sorted(res, reverse=True, key=int))))