We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intis_max(inta,intb){return(a>b)?0:1;}intmain(){intn;scanf("%d",&n);assert(n>=5);assert(n<=200000);int*types=malloc(sizeof(int)*n);for(inttypes_i=0;types_i<n;types_i++){scanf("%d",&types[types_i]);}// your code goes hereint*counts=malloc(sizeof(int)*n);intmax_i=0;intglobal_max=0;for(inti=0;i<n;i++){counts[types[i]-1]++;if(is_max(global_max,counts[types[i]-1])==1){global_max=counts[types[i]-1];max_i=types[i]-1;}}printf("%d",max_i+1);free(types);free(counts);return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Migratory Birds
You are viewing a single comment's thread. Return to all comments →
Yes, it can be done like this: