Why am I getting SIGSEGV for this problem, MAJORITY, I have solved the problem using boyer-moore voting technique,but my solution is not getting accepted using hashing array,can someone please help me by figuring out the bug in my code?
link to my code is https://ideone.com/uifxtm
#include <bits/stdc++.h>
using namespace std;
#define MAX 2002
int main()
{
int t;scanf("%d",&t);
while(t–)
{
int arr[MAX],i;for(i=0;i<MAX;i++)arr[i]=0;
int n,num,ans;
int hz=1000;bool fg=false;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&num);
arr[num+hz]++;
if(arr[num+hz]>n/2)
{
fg=true;ans=num;break;
}
}
if(fg)
{
printf(“YES %d\n”,ans);
}
else printf(“NO\n”);
}
}