I want to solve this question using dict in python.However i am not able to create code out of the logic. question says Given an array A[] of integers, sort the array according to frequency of elements. That is elements that have higher frequency come first. If frequencies of two elements are same, then smaller number comes first. Input: 2
5
5 5 4 6 4
5
9 9 9 2 5
Output:
4 4 5 5 6
9 9 9 2 5
t=int(input())
for i in range(t):
n=int(input())
arr=list(map(int,input().split()))
d={}
for i in arr:
d[i]=d.get(0,i)+1
a=max(d[i])
print(i*d[i])
a=a+1
Little bit of code that I tried is as above