Function to check if the candidate occurs more than n / 2 times
function isMajority ( $ a , $ size , $ cand ) { $ count = 0 ; for ( $ i = 0 ; $ i < $ size ; $ i ++ ) if ( $ a [ $ i ] == $ cand ) $ count ++ ; if ( $ count > $ size / 2 ) return 1 ; else return 0 ; }