count of maximum

#include <stdio.h>
void p(int [],int );
int main(int argc, char **argv)
{

int t,k,i,n,freq[10001];
scanf("%d\n",&t);

while(t--)
{
	for(i=0;i<10001;i++)
	 freq[i]=0;
	 
	scanf("%d\n",&k);
	
	for(i=1;i<=k;i++)
	{
		scanf("%d",&n);
		freq[n]++;
	
	}
	p(freq,k);
}
return 0;

}

void p(int a[],int r)
{
int temp=0,nomax=1,i=1;

for(i=1;i<=r;i++)
{
	
	if(temp<a[i])
	{
	temp=a[i];
	nomax=i;
    }
     else if(a[i]==temp)
        {
            if(nomax>i)
                nomax=i;
            temp=a[i];
        }
   
    
}

printf("%d %d\n",nomax,temp);

}

why am i getting wrong answer for this ??

This is straight away wrong code. Say k = 3 and input numbers are 4 4 4, so freq[4] = 3 and all other 0.
When you pass freq to function p as variable a, then a[4] = 3, and other a[i] = 0. But in loop i = 0 to r, you are checking only a[1],a[2] and a[3] which are all zero. You are not even touching a[4].

1 Like

i modified the loop to go till r+1 still it is giving WA…!

got an ac thanks a lot !!!

//