Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first.
Input
First line of input contains an integer T, denoting the number of test cases. Then follows description of T cases. Each case begins with a single integer N, the length of A. Then follow N space separated integers in next line. Assume that 1 <= T <= 100, 1 <= N <= 100 and for all i in [1..N] : 1 <= A[i] <= 10000
Output
For each test case, output two space separated integers V & C. V is the value which occurs maximum number of times and C is its count.
Example
Input:
2
5
1 2 3 2 5
6
1 2 2 1 1 2
Output:
2 2
1 3
Solution:
#include
int count[100000];
int main()
{
int arr[100],n,t,min,val,i,max, index;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i
{
scanf("%d",&arr[i]);
count[arr[i]]++;
}
max=count[arr[0]];
index=arr[0];
count[arr[0]]=0;
for(i=0;i
{
if(max
{
max=count[arr[i]];
index=arr[i];
}
else if(max==count[arr[i]] && index>arr[i])
index=arr[i];
}
printf("%d %d\n",index,max);
for(i=0;i count[arr[i]]=0;
}
return 0;
}