By swapping we can adjust array only when the frequency of the element which occurs most is less than or equal to ( n + 1 ) / 2 .
if ( mx > ( n + 1 ) / 2 ) { Console . WriteLine ( " NO " ) ; } else { Console . WriteLine ( " YES " ) ; } }