Doubt Regarding the checking of solutions to problem " RRCOPY " for different test cases

Dear codechef Team, i just wanted to ask that what is wrong with my solution as thought it matches the pseudo code of the editorial…
Also for the folloeing TEST CASE :
Input :
1
4
1 7 9 7

output:
3

As my solution gave the correct answer for this test case but my friend’s solution did not gave correct answer fro this but still it got AC and i got WA
Here is my solution:

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
	int t,n,a[100005],x,l=0,max=0;
	for(int i=0;i<100006;i++)
	a[i]=0;
	cin>>t;
	while(t--)
	{	l=0;
		cin>>n;
		for(int i=1;i<=n;i++)
		{cin>>x;a[x]=x;}
		for(int i=1;i<100006;i++)
		{if(a[i]) l++; }
		cout<<l<<"\n";
		
	}
	return 0;
}

And here is my friends solution:

#include<stdio.h>
int main()
{
	int i,t,n,a,j,b[100001],size;
	scanf("%d",&t);
	while(t--)
	{
		size=0;
		scanf("%d",&n);
		for(i=0;i<n;i++)
		b[i]=0;
		for(i=0;i<n;i++)
		{
		  scanf("%d",&a);
		  b[a-1]=-1;
	    }
		for(i=0;i<n;i++)
		{
		  if(b[i]==-1)
		  size++;
		}
		printf("%d\n",size);
		
	}	
	return 0;
}  

I don’t want to point on someones solution but want to know if i m going some where wrong !!!
Pls Help !!!

you need to refresh your a array inside the while(t–) loop

1 Like

How the correct answer is 3 ? there are 1,4,7,9 i.e 4 distinct values here. So ,the array needs to be at least 4. and you also need to set array to zero for every test case.

1 Like

Thnx yrr got it …
such a small thing i just missed.such a fool i was ???
Once again thnx :slight_smile:

my friend you are just interpreting the input wrong
the INPUT was: 1 4 1 7 9 7
THis means " 1 " is fro no of test cases and then " 4 " is fro size of N and then " 1 7 9 7 " is for array elements
I think now it may help you