Help me in solving MISSP problem

My issue

this code is equivalent to the usage of map data structure.
why it is giving wrong answer.
logic is correct to my knowledge.

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	    int arr[n];
	    int count[100002];
	    for(int i=0;i<n;i++){
	        cin>>arr[i];
	        count[arr[i]]++;
	    }
	    for(int i=0;i<100002;i++){
	        if(count[i]%2!=0){
	            cout<<i<<endl;
	            break;
	        }
	    }
	}
	return 0;
}

Problem Link: MISSP Problem - CodeChef

@shiwani_143 i guess so your logic is correct but this question becomes lot easier with maps …
I have pasted my code below
hope this helps!!

include <bits/stdc++.h>
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{ int n;cin>>n; int ans=0;
unordered_map<int,int>mp;
for(int i=0;i<n;i++)
{
int b;
cin>>b;
mp[b]++;
}
for(auto it:mp)
{
if(it.second%2 != 0)
{
ans = it.first;
break;
}
}
cout<<ans<<endl;
}
return 0;
}

i know maps make it easier but why it is giving wrong output in my case.

Try initializing the count array with zero.
int count[100002] = {0};
I think the array is initialized with garbage values.

1 Like