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 ) cout << " NO " << endl ; else cout << " YES " << endl ; }