I have gone through many test cases,yet I think I might be missing some special case or am making some silly mistake. Can anyone please help me out with the wrong answer…??
Here is my code in C:-
#include<stdio.h>
int main()
{
long int t,n,max=0,k,l,i,nummax=0,num;
scanf("%ld",&t);
if (t < 1 || t > 100)
return -1;
while(t--)
{
scanf("%ld",&n);
// nummax=0,max=0,k=0,l=0,i=1;
if (n < 1 || n > 100)
return -1;
long int arr[10000]={0};
for(i=1;i<=n;i++)
{
scanf("%ld",&num);
if (num < 1 && num > 10000)
return -1;
if (num>nummax)
nummax=num;
arr[num]=arr[num]+1;
}
/*for(i=1;i<=n;i++)
printf("%ld",arr[i]);
*/
max=arr[1];
k=1;
for(i=1;i<=nummax;i++)
{
if (arr[i+1]>max)
{
max=arr[i+1];
k=i+1;
}
else if (arr[i+1]==max)
{
max=arr[i+1];
l=i+1;
}
}
//printf("%ld %ld\n",k,l);
if (arr[k]==max && arr[l]==max)
{
if (k>l)
printf("%ld %ld\n",l,arr[l]);
else
printf("%ld %ld\n",k,arr[k]);
}
else
printf("%ld %ld\n",k,arr[k]);
}
return 0;
}