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 ) System . out . println ( " NO " ) ; else System . out . println ( " YES " ) ; }