ANSLEAK question what is better approach than this? link:https://www.codechef.com/APRIL20B/problems/ANSLEAK

what is more better approach than this one, for worst case to get one ans correct means that answer is same for all questions , otherwise worst case will always be 0. I got only 37 points .

#include
using namespace std;

int main() {
int t;
cin>>t;
while(t–)
{
int n,m,k,ind,max=0,i,j;
cin>>n>>m>>k;
int f[m+1],a[k];
for(i=0;i<n;i++)
{max=0; ind=0;
for(j=0;j<m+1;j++)
{
f[j]=0;
}
for(j=0;j<k;j++)
{
cin>>a[j];
f[a[j]]++;
}
for(j=0;j<m+1;j++)
{
if(max<f[j])
{
max=a[j];
ind=j;
}

}
cout<<ind<<endl;

}
} return 0;
}

int main(void) {
int t,n,m,k;
scanf("%d",&t);
while(t-- >0)
{
scanf("%d",&n);
scanf("%d",&m);
scanf("%d",&k);
int arr[n][k];
int c[m];
for(int i=0;i<n;i++)
{
for(int v=0;v<m;v++)
{
c[v]=0;
}
for(int j=0;j<k;j++)
{
scanf("%d",&arr[i][j]);
c[arr[i][j]-1]++;
}
int big=c[0];
int p=0;
for(int u=1;u<m;u++)
{
if(c[u]>big)
{
big=c[u];
p=u;
}
}
printf("%d ",p+1);
}
}
return 0;
}
Similar approach though I got 73 points
hope this helps😄

thanks!

https://www.codechef.com/viewsolution/32448489
See this bro (84 points)

1 Like

See my approach(93.8).
https://www.codechef.com/viewsolution/31771310

2 Likes