Monk being monitor

3.8

4 votes
Sorting
Problem

Monk being the monitor of the class needs to have all the information about the class students. He is very busy with many tasks related to the same, so he asked his friend Mishki for her help in one task. She will be given heights of all the students present in the class and she needs to choose 2 students having heights h1 and h2 respectively, such that h1>h2 and difference between the number of students having height h1 and number of students having height h2 is maximum.

Note: The difference should be greater than 0.

Video approach to solve this question: here

As Mishki has never been a monitor of the class, help her in the same. If there exists such students, then print the required difference else print "1" (without quotes).

Input:
The first line will consists of one integer T, which denotes the number of test cases.
For each test case:
One line consists of a integer N, denotes the number of students in the class.
Second line contains N space separated integers, where ith integer denotes the height of the ith student in the class.

Output:

For each test case, if the required difference exists then print its value, otherwise print 1. Print the answer for each test case in a new line.

Constraints:
1T10
1N105
1height of the student106

Sample Input
1
6
3 1 3 2 3 2
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here T=1 and N = 6.

Number of students having height = 3 is 3.
Number of students having height = 2 is 2.
Number of students having height = 1 is 1.

Here Mishki can choose students with height=3 (h1) and height = 1 (h2) , as the difference between number of students having height (h1) and number of students having height (h2) is maximum and greater than 0.

Contributers:
Editor Image

?