Frequency Sort

4

3 votes
Easy
Problem

You are given an array A of a size N.You have to output the elements in non-increasing order of the frequencies. If two numbers have the same frequency print the smaller element first.

Input:

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains a single integer N.
  • The next line contains the array A.

Output: 

For each test case print the elements with their frequencies in non-increasing order.

Constraints:

1≤T≤1,000

1≤N≤1,000

1≤A[i]≤106

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?