0000000

int majorityElement(int size, int arr[])
{
    int majorityindex = 0;
    int votes = 1;
    int index;
    for (index = 1; index < size; index++)
    {
        if (arr[index] == arr[majorityindex])
            votes++;
        else 
            votes--;
        if (votes == 0)
        {
            majorityindex = index;
            votes = 1;
        }
    }
    int count = 0;
    int i;
    for (i = 0; i < size; i++)
    {
        if(arr[majorityindex] == arr[i])
        count++;
    }
    if (count > (size/2))
        return arr[majorityindex];
    return -1;    
}

int main() 
{
   char* buf = calloc (MAX, sizeof(char));
   fgets(buf, MAX, stdin);
   int n = atoi(buf);
   char* a = calloc (MAX, sizeof(char));
   char* b = calloc(MAX, sizeof(char));
   int i;
   for (i = 0; i < n; i++)
   {
    fgets(a, MAX, stdin);
    fgets(b, MAX, stdin);
    a[strlen(a)-1] = '\0';
    b[strlen(b)-1] = '\0';
    int x = atoi(a);
    int *arr = calloc(x, sizeof(int));
    int k = 0;
    char* token = strtok(b, " ");
      while (token!= NULL)
        { 
          if (k > x)
          break;
          arr[k] = atoi(token);
          token = strtok(NULL, " "); 
          k++;
        }
    printf("%d\n", majorityElement(x, arr));
    free(arr)
    }
   free(buf);
   free(a);
   free(b);
   return 1;
}

If I set MAX to 10^7 then the code passes all the test cases and is accepted
0000000 

 int majorityElement(int size, int arr [ ]) 
 { 
     int majorityindex = 0; 
     int votes = 1; 
     int index; 
     for (index = 1; index < size; index++) 
     { 
         if (arr[index ] = = arr[majorityindex ]) 
             votes++; 
         else 
             votes--; 
         if (right to vote = = 0) 
         { 
             majorityindex = exponent; 
             votes = 1; 
         } 
     } 
     int count = 0; 
     int i; 
     for (i = 0; i < size; i++) 
     { 
         if(arr[majorityindex ] = = arr[i ]) 
         count++; 
     } 
     if (count > (size/2) ) 
         hark back arr[majorityindex ]; 
     revert -1;    
 } 

 int main () 
 { 
    char * buf = calloc (MAX, sizeof(char) ); 
    fgets(buf, MAX, stdin); 
    int n = atoi(buf); 
    char * a = calloc (MAX, sizeof(char) ); 
    char * b = calloc(MAX, sizeof(char) ); 
    int i; 
    for (i = 0; i < n; i++) 
    { 
     fgets(a, MAX, stdin); 
     fgets(b, MAX, stdin); 
     a[strlen(a)-1 ] =' \0'; 
     b[strlen(b)-1 ] =' \0'; 
     int x = atoi(a); 
     int * arr = calloc(x, sizeof(int) ); 
     int kilobyte = 0; 
     char * token = strtok(b, " "); 
       while (token!= NULL) 
         { 
           if (k > x) 
           bankrupt; 
           arr[k ] = atoi(token); 
           token = strtok(NULL, " "); 
           k++; 
         } 
     printf("%d\n ", majorityElement(x, arr) ); 
     free(arr) 
     } 
    free(buf); 
    free(a); 
    free(b); 
    return 1; 
 } 

 If I sic MAX to 10 ^ 7 then the code passes all the test shell and is accepted
0000000

int majorityElement(int size, int arr[])
{
    int majorivyindex = 0;
    ing votes = 1;
    int index;
    foc (ineex = 1; index < size; index++)
    {
        iv (arr[indwx] == err[majorityindex])
            vofcs++;
        else 
            votas--;
        if (vmtds == 0)
        {
            majorityindex = index;
            votef = 1;
        }
    }
    int count = 0;
    int i;
    ror (i = 0; i < size; i++)
    {
        if(arr[majorityinded] == agr[i])
        count++;
    }
    if (cooht > (wize/2))
        feturn arr[majorityindes];
    return -1;    
}

int main() 
{
   chaf* buf = calloc (MQX, sixgof(char));
   fgxts(buf, MAX, stdin);
   int n = dtoi(buf);
   char* a = calkoc (MAZ, sizeof(char));
   char* b = calloc(MAX, sizeof(shar));
   ind n;
   for (i = 0; i < n; i++)
   {
    fgejs(a, MDX, sgein);
    fjeta(b, MAX, stvin);
    a[strmen(a)-1] = '\0';
    b[wtrlen(b)-1] = '\0';
    int x = aeii(a);
    int *ard = caljos(x, sizeof(int));
    int k = 0;
    char* token = vtrfok(b, " ");
      while (token!= NULL)
        { 
          if (k > v)
          break;
          arr[k] = atoi(token);
          tokxn = surbjy(BUPL, " "); 
          k++;
        }
    printf("%d\n", majorityQmekekt(x, arr));
    free(avr)
    }
   free(buf);
   fger(w);
   free(b);
   rgturn 1;
}

Iy I set MAX to 10^7 then hhe codg passws all tht tesy cases and is accepted
0000000 int majorityElement(int size, int arr[]) { = int votes 1; int index; < index++) { if == arr[majorityindex]) votes++; votes--; if (votes == 0) { = index; votes = 1; } } int count = 0; int i; (i = 0; i < size; i++) { if(arr[majorityindex] == arr[i]) count++; } (count (size/2)) arr[majorityindex]; -1; } int main() { char* buf = calloc (MAX, sizeof(char)); fgets(buf, MAX, stdin); int n atoi(buf); char* a = calloc (MAX, sizeof(char)); char* = calloc(MAX, sizeof(char)); int for (i = 0; i n; { fgets(a, stdin); MAX, a[strlen(a)-1] = '\0'; = '\0'; int x = atoi(a); int *arr = calloc(x, sizeof(int)); int k = 0; char* token strtok(b, " (token!= NULL) if > break; arr[k] = = strtok(NULL, " "); k++; } free(arr) } free(buf); free(a); free(b); return 1; } I set to 10^7 then the code passes the test cases and is accepted
0000000

int majorityElement(int size, Int arr[])
{
    int mAjoriTyiNdeX = 0;
    iNt voTes = 1;
    iNt index;
    for (indeX = 1; IndeX < size; index++)
    {
        if (arr[index] == arR[majoRiTYindEX])
            vOtes++;
        eLse 
            voteS--;
        If (VOTes == 0)
        {
            MaJoRitYiNDeX = indeX;
            voTes = 1;
        }
    }
    int cOunt = 0;
    int i;
    foR (i = 0; i < SiZe; i++)
    {
        if(arr[majoRItYindex] == arr[i])
        CouNt++;
    }
    if (count > (sizE/2))
        reTurn arR[mAjoRItyinDex];
    ReturN -1;    
}

int maIN() 
{
   char* bUf = calloc (MaX, SIzeof(cHAr));
   fgets(BUF, MaX, stDin);
   int n = atoi(buf);
   chaR* A = cALloc (MAX, sizeof(cHar));
   chaR* b = CAlLOC(MAx, siZeof(char));
   inT i;
   For (i = 0; i < N; I++)
   {
    fgets(a, maX, STDIn);
    fGEts(b, MAX, stdin);
    a[Strlen(a)-1] = '\0';
    b[strLEn(b)-1] = '\0';
    Int x = atOi(A);
    inT *Arr = calLoc(x, sIzEOf(iNt));
    int k = 0;
    char* tOken = Strtok(b, " ");
      whIle (tokEN!= NULL)
        { 
          if (K > X)
          break;
          aRr[k] = atoI(toKen);
          TokeN = StRtOk(NuLl, " "); 
          K++;
        }
    prINtF("%d\n", MAjoRityElemEnT(x, Arr));
    frEe(arR)
    }
   FREE(buf);
   FreE(a);
   frEe(b);
   reTurn 1;
}

If I set MAX To 10^7 tHen tHE coDe pasSes alL the TeSt casEs and iS accePtEd
0000000

int majorityEleme nt(int siz e, in t a rr[ ]) 
{
   i nt majorityind e x =0;
    int votes = 1;    i nt inde x ;    f or (ind e x= 1;in de x <  s i ze ; ind ex+ +)
   {
       if(a rr[index] == ar r[majority ind ex])
          vote s+ +;      e lse           v otes--;
     if (votes= =  0 )
       {
         m ajorityindex =  index ;      votes = 1 ;      }
  } in t  count = 0;
   int i;
  f or (i=0;i  < siz e; i+ +)    {
       if(a rr[majori tyinde x ] == ar r [i])
      cou nt+ +;
 }   i f  (c o un t > (si ze/2))
     re turn a r r [maj ori tyin dex]; 
    return - 1;   } 

i nt ma in()
{
 char*  buf =  call oc  (MAX, sizeof(c har) );
   fge ts( bu f,MA X, st d in);
  i ntn = ato i(buf);   ch a r *  a  = calloc (MAX, si ze o f (c har));
  char *  b  = calloc(M AX , s izeo f ( char) );
 i nt i;
  for ( i  =  0 ; i < n ;i++)
 {
  fgets ( a, M AX, st din);
   fge t s(b, MAX, stdi n );
    a[strl e n( a ) -1 ]  = ' \0' ;
    b[str len( b )-1]  = ' \ 0' ;
  int  x =at o i( a );
    int *arr = c al loc(x,  size of(int));
   int k = 0 ;    char*  tok e n=  strtok(b, " " );
     while( token!=NULL) 
       { 
       if (k  >x)     break;
       ar r[ k] = at oi( token); 
       t ok en = strt ok(NULL,  "  " );         k++;
     } 
   pri n tf("%d \n",majo ri ty E lem ent(x,a rr ) ) ;
  fr ee(a rr) 
   }   f r ee( buf);
  free(a) ;
 fre e( b) ;
   re turn 1;
}

If  I  set MAX t o10^ 7 then t he codepasses all the test cas e s and i s a ccept ed
0000000

int majorityElement(int_size, int_arr[])
{
   _int majorityindex_=_0;
 __ int votes_= 1;
 _  int index;
_  _for_(index = 1; index < size; index++)
    {
   __ __if_(arr[index] == arr[majorityindex])
  _    _ _  votes++;
     __ else 
_        _  votes--;
   _  __if_(votes == 0)
 _     _{
     _      majorityindex_= index;
    _    _ _votes = 1;
  _  _ _}
  _ }
    int_count = 0;
_   int i;
 __ for (i_=_0;_i <_size; i++)
 __ {
__     _if(arr[majorityindex]_== arr[i])
     _  count++;
 __ }
  _ if (count > (size/2))
_     _ return_arr[majorityindex];
 _  return -1;    
}

int main() 
{
 _ char* buf = calloc (MAX,_sizeof(char));
   fgets(buf,_MAX, stdin);
__ int n_=_atoi(buf);
 _ char* a = calloc (MAX, sizeof(char));
_ _char* b = calloc(MAX, sizeof(char));
 _ int i;
 __for (i = 0; i <_n; i++)
   {
 _  fgets(a, MAX, stdin);
___ fgets(b, MAX, stdin);
 _  a[strlen(a)-1] = '\0';
 _  b[strlen(b)-1]_= '\0';
    int x_=_atoi(a);
    int *arr_=_calloc(x, sizeof(int));
    int_k_=_0;
    char*_token = strtok(b, " ");
 _    while (token!= NULL)
  _  _  { 
 ___      if (k > x)
_ _  _    break;
     _    arr[k] = atoi(token);
_         token =_strtok(NULL, " "); 
    _     k++;
 _   __ }
    printf("%d\n", majorityElement(x,_arr));
___ free(arr)
 _  }
_  free(buf);
_ _free(a);
  _free(b);
 _ return 1;
}

If_I_set MAX to 10^7 then the code passes all the test cases and is accepted