Again traverse the array and find the actual counts .
for ( $ i = 0 ; $ i < $ n ; $ i ++ ) { if ( $ arr [ $ i ] == $ first ) $ count1 ++ ; else if ( $ arr [ $ i ] == $ second ) $ count2 ++ ; } if ( $ count1 > $ n / 3 ) return $ first ; if ( $ count2 > $ n / 3 ) return $ second ; return -1 ; }