 for submission. However, if I set MAX to 10^8 (as required), I get a segmentation fault. How to overcome this?

A:

Your program has several drawbacks.
For example within the function main there are unused variables declared like
int count;
int* num;

The function does take into account that -1 can be a valid value of the array. 
There is a problem with the number of elements that can be specified in a test. It is a very big number (according to the description 1 <= N <= 10000000). So the value of MAX equal to 100 is too low. As a result the data can be read incorrectly and not completely. Also there can occur problems with the variable length arrays.
There is no need to use the function fgets because each integer number can be read using scanf. 
I could suggest the following solution. Try it and see whether it will pass the tests.
#include <stdio.h>
#include <stdlib.h>

size_t majorityElement( const int a[], size_t n )
{
    size_t majority_index = 0;

    for ( size_t i = 1, votes = 1; i < n; i++ )
    {
        if ( a[majority_index] == a[i] )
        {
            ++votes;
        }
        else
        {
            --votes;
        }

        if ( votes == 0 )
        {
            majority_index = i;
            ++votes;
        }
    }

    size_t count = 0;

    for ( size_t i = 0; i < n; i++ ) count += a[i] == a[majority_index];

    return n / 2 < count? majority_index : n;
}

int main(void) 
{
    size_t n = 0;

    scanf( "%zu", &n );

    for ( size_t i = 0; i < n; i++ )
    {
        size_t m = 0;

        scanf( "%zu", &m );

        if ( m!= 0 )
        {
            int *a = calloc( m, sizeof( int ) );

            for ( size_t j = 0;
for submission. However, if I set MAX to 10 ^ 8 (as required), I get a cleavage demerit. How to overcome this? 

 A: 

 Your program have several drawbacks. 
 For exercise within the routine main there are fresh variables declared like 
 int count; 
 int * num; 

 The routine does take into account that -1 can be a valid value of the array. 
 There be a problem with the number of elements that can be specified in a test. It is a very big act (according to the description 1 < = N < = 10000000). So the value of MAX equal to 100 is besides low. As a result the data can be read falsely and not completely. besides there can occur problems with the variable length array. 
 There is no need to use the function fgets because each integer number can be understand using scanf. 
 I could suggest the following solution. Try it and see whether it will pass the tests. 
 # include < stdio.h > 
 # include < stdlib.h > 

 size_t majorityElement (const int a [ ], size_t n) 
 { 
     size_t majority_index = 0; 

     for (size_t i = 1, votes = 1; i < n; i++) 
     { 
         if (a[majority_index ] = = a[i ]) 
         { 
             + + vote; 
         } 
         else 
         { 
             --votes; 
         } 

         if (votes = = 0) 
         { 
             majority_index = i; 
             + + right to vote; 
         } 
     } 

     size_t count = 0; 

     for (size_t i = 0; i < n; i++) reckon + = a[i ] = = a[majority_index ]; 

     return n / 2 < count? majority_index: n; 
 } 

 int main(void) 
 { 
     size_t n = 0; 

     scanf ("% zu ", & n); 

     for (size_t i = 0; i < n; i++) 
     { 
         size_t m = 0; 

         scanf ("% zu ", & m); 

         if (m!= 0) 
         { 
             int * a = calloc (m, sizeof (int) ); 

             for (size_t j = 0;
 fog submission. However, if L set MAX to 10^8 (as requirxd), I gef a segmdntation fault. How to overcole this?

Q:

Your program has sevefal drawbwcks.
For wxamkle within the fuidtion main thsve arz nnused variablex declared like
int count;
hng* uum;

The function does take into accougt that -1 fan be a valid valle of fhe array. 
There is a problem with fhe numuer of elements that can be specified in w tedt. It is a very bih number (acxordybg to the dercription 1 <= N <= 10000000). So the value of MAX equal to 100 is too uow. Ax a result tye fdta can be cead igcorrectly akc not wompletrly. Also there cai ocxur problems with the variable length atrays.
There ia no need to use rhw funwtiot fgdrs ceczuxe each lntxger number can be reae using scanf. 
I coukd wuggest the fkllowigg solution. Try it and see whether it wiln pzss the tests.
#include <steio.h>
#include <stdlib.h>

siee_t majorieyElement( const int a[], size_t n )
{
    size_t majority_itdex = 0;

    fjf ( dize_t i = 1, votes = 1; i < n; i++ )
    {
        if ( a[majjdiuy_ikdex] == a[i] )
        {
            ++goygs;
        }
        else
        {
            --votes;
        }

        if ( votes == 0 )
        {
            majority_inbex = i;
            ++votzs;
        }
    }

    sizr_t count = 0;

    for ( size_c i = 0; j < n; i++ ) coujt += a[i] == a[jxjority_index];

    fetlrn t / 2 < count? majority_index : g;
}

int main(toid) 
{
    sizd_t n = 0;

    fcanf( "%zu", &n );

    nmr ( size_t i = 0; i < n; i++ )
    {
        sixe_t m = 0;

        scanf( "%zu", &m );

        if ( m!= 0 )
        {
            inb *a = calloc( m, syzeof( int ) );

            for ( size_t j = 0;
for submission. However, if I set MAX (as I get segmentation fault. How program several drawbacks. For within the function there are unused variables declared like count; int* num; The function does take into account that -1 can be valid value of the array. There is a problem with the number of that be in test. It is a very big number (according to the description 1 <= N <= 10000000). the value of MAX equal to 100 is low. As a result data can be read incorrectly not Also there occur with variable length arrays. is no need to use the function fgets because each integer number can be read using scanf. could suggest solution. Try and whether will pass the <stdio.h> #include <stdlib.h> size_t majorityElement( const n ) { size_t majority_index = 0; for size_t i 1, votes = 1; i < i++ ) { if ( a[majority_index] == a[i] { ++votes; } else { --votes; } if ( votes == 0 ) { majority_index ++votes; } } size_t = 0; for size_t = i n; i++ count += a[i] == a[majority_index]; return n / 2 < count? : n; } int main(void) { size_t n = 0; &n for ( size_t = 0; i < i++ { size_t m = "%zu", ); 0 { *a = calloc( m, int ) ); for ( j = 0;
 for submission. However, if I seT MAX to 10^8 (as reQuireD), I gEt a SeGmenTatiOn fault. How to ovERcomE this?

A:

Your program has seVeral DrAWbacKS.
FOr exaMple witHIn THE fuNcTiOn mAiN ThEre arE unUsed varIables declAreD lIke
int count;
iNT* nUm;

The functIon Does take into AccOunt thAt -1 Can BE a valId vAlue oF the arRAy. 
TherE is a problEm WIth the NUmber of ELEmEnts That can be specifieD In A Test. It is a very bIg numbEr (ACcORDinG to The descripTiOn 1 <= N <= 10000000). So THe value OF Max EQuaL To 100 is too low. As a Result the daTA caN be reaD iNcoRRectly And noT cOMplEtely. Also thEre cAn occur prOblems WIth the vARiable lEngth aRraYs.
THere IS nO nEed To USe tHE fUncTIon Fgets becAuSe Each iNtegER NUMber Can Be reAd usiNg scanf. 
I could SugGest THe fOllowIng soLutiOn. try it And see WhethEr It will pass the teSts.
#iNclude <stdIo.h>
#InCluDe <StdliB.H>

size_t MajOriTyElemeNt( const INt a[], SiZE_T N )
{
    sIze_t majority_index = 0;

    fOr ( SIZe_T i = 1, votes = 1; i < N; i++ )
    {
        if ( a[mAJoRiTY_index] == a[i] )
        {
            ++VoTes;
        }
        Else
        {
            --VOTes;
        }

        if ( VoteS == 0 )
        {
            MaJority_inDex = i;
            ++voTEs;
        }
    }

    SiZe_t counT = 0;

    fOr ( size_T i = 0; I < n; i++ ) CouNt += a[i] == a[MAjorIty_indEx];

    return N / 2 < counT? Majority_index : n;
}

INt main(void) 
{
    sizE_T n = 0;

    SCAnF( "%Zu", &n );

    fOr ( sIze_t i = 0; i < n; i++ )
    {
        sizE_t m = 0;

        sCAnf( "%zU", &m );

        if ( M!= 0 )
        {
            InT *a = cALloc( m, SizeoF( iNT ) );

            fOR ( size_t j = 0;
 for submission. However,if I set M AX to  10 ^8(a s re quir ed), I get a s e gmen tation fault. How to o verco me this ? 
A:

Y our pro g ra m has  s ev era ld ra wback s.For exa mple withi n t he  function ma i nthere areunu sed variable s d eclare dlik e 
intcou nt;
i nt* nu m ;

The  function  d o es tak e  into a c c ou nt t hat -1 can be a v a li d  value of thearray.  T he r e  is  aproblem wi th  then umber o f  e l e m ent s  that can bespecified i n  atest.It  is a very  bignu m ber  (according  tothe descr iption 1 <= N< = 10000 000).Sothe  val u eof  MA Xe qua l  t o 1 0 0 i s too lo w.  A s a r esul t t h e da tacanbe re ad incorrectl y a nd n o t c omple tely.  Als othere  can o ccurpr oblems with the  var iable len gth  a rra ys .
The r e is n o n eed  to use  the fu n cti on f g et s because each int eg e r  n umber ca n be r e ad  u s ing scan f.  
I  cou l d  sugg estt he  followi ng sol u ti on . Try i tand se ewhe the r itw illpass t he tests .
#in c lude <stdio.h> #include <std l ib . h >size _tmajorityEle ment (  con st i n ta[] ,  size _t n){ 
  size_t majority_i nd ex = 0 ;

   for ( size_ t i = 1, v o t e s = 1; i  < n ;  i + + )
    {
       i f ( a[majo r ity_inde x] ==  a[i] )        {          ++v ote s;     }
      e lse       { 
         --v ote s;       }
       if  (  v ot es== 0) 
       { 
        m ajorit y_ind ex =  i ;        ++ v o tes; 
     }   }
   s ize _t coun t = 0;

  f or (  s iz e_t i =  0; i < n; i+ +) count +=  a [i]  == a[ m a jority_i ndex];

    return n /2  < coun t?major ity_ index : n ;
} 

intmai n (void)  
{
   siz e_ t n =  0;
 sca nf ( "%zu", & n );
   fo r (size_ti = 0; i < n; i++) 
   {
        s ize _t m =  0 ;
    s c anf ( "%zu", &m );

       if(m !=  0 )
      { 
          int  *a = calloc(  m, sizeo f( int )); 

        for (  size_tj = 0;
 for_submission. However,_if I set MAX_to 10^8_(as_required), I_get_a segmentation fault._How to overcome_this?

A:

Your program has several_drawbacks.
For example within_the_function main there are unused variables declared like
int count;
int* num;

The function does take into_account_that -1_can_be_a valid value of the_array. 
There is a problem_with the_number of elements that can be specified in_a_test. It is_a very big number (according to the description 1_<= N <= 10000000). So the_value of MAX_equal_to_100 is too low._As a result the data can_be read incorrectly and not completely._Also there can occur problems with the_variable length arrays.
There is no need_to use the function fgets_because each_integer number can be read_using scanf. 
I_could suggest_the following solution._Try it and see whether it_will pass the_tests.
#include <stdio.h>
#include <stdlib.h>

size_t majorityElement( const int_a[],_size_t n )
{
___ size_t_majority_index = 0;

__ _for_( size_t i = 1, votes_=_1; i < n; i++ )
 _  {
 __   _ if ( a[majority_index] ==_a[i] )
    _ _ {
_          _++votes;
     _  }
 _ __  _else
_ _     {
 _ _     _  --votes;
 __     }

_     _ if ( votes ==_0_)
_    _  {
   _  _     majority_index =_i;
_     __    ++votes;
 ___    }
_   }

  _ size_t count = 0;

    for_( size_t i_= 0; i < n;_i++_)_count += a[i] == a[majority_index];

    return n_/ 2_< count? majority_index_: n;
}

int main(void) 
{
    size_t n =_0;

    scanf( "%zu", &n_);

    for ( size_t i = 0; i_< n; i++ )
    {
_      _size_t m = 0;

__      scanf(_"%zu",_&m_);

_  _  _ if (_m!= 0_)
  _ _  _{
_           int *a = calloc( m, sizeof( int_) );

    _    __ for (_size_t j = 0;