Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Count of maximum

$
0
0

why is the following showing wrong answer on codechef though it gives the correct answer for the test cases provided and several other cases that i fed into the program. Here is the question:

http://www.codechef.com/problems/MAXCOUNT

and here is the code

#include<stdio.h>
#include<string.h>
int main()
{
    int t,n,a,num[10001],freq,val;
    scanf("%d",&t);
    while(t--)
    {
        memset(num,0,10001);
        scanf("%d",&n);
        freq=0;
        val=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a);
            num[a]++;
            if(freq<num[a])
            {
                freq=num[a];
                val=a;
            }
        }
        printf("%d %d\n",val,freq);
    }
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>