please tell which test case is not working my code is correct please help

#include<iostream>

using namespace std;

int main()

{

int t;
scanf("%d",&t);
int ans=0;
while(t--)
{
	
	int n;
	scanf("%d",&n);
	int arr[n];
	int z[10000];
	memset(z,0,10000);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
		
		
			z[arr[i]]=z[arr[i]]+1;
		
	}
		int max=0;
		int ind=0;
	for(int j=0;j<n;j++)
	{
		
	
		if(z[arr[j]]>max)
		{
			max=z[arr[j]];
			ind=j;
		}
		
	}
	printf("%d",arr[ind]);
	printf(" ");
	printf("%d",max);
	
}

}

getting wrong answer please help

Add a newline character after the output…! :slight_smile:

printf("%d",arr[ind]);
printf(" ");
printf("%d\n",max);

Just add ‘\n’ after printf.

work on this…
In case of ties, choose the smaller element first.
it is not handled in your case…
and also increase the size of array z to 10001, actually, you need to count integer 10000 also… so z[10000]++ will give runtime error in your case

1 Like

@ dracowane thanks a lot i understood it now !!

Corrections in your code ->

  1. you have to reinitialize the ans to 0, you have not done that,

  2. also add return 0 before main() ends,

@rjohari23 it is not necessary to write ‘return 0’ if you are using C++ . It automatically returns 0 if nothing is mentioned ,
quoting from bjarne stroutrup :-
"

It’s also worth noting that in C++, int main() can be left without a return value at which point it defaults to returning 0. This is also true with a C99 program. Whether return 0 should be omitted or not is open to debate .

memset(z,0,10000) is the mistake in your code.

it should be memset(z,0,sizeof(z)).

Thanks.