Find the possible permutation of the bits of N | Java implementation of the approach ; Function that returns true if it is possible to arrange the bits of n in alternate fashion ; To store the count of 1 s in the binary representation of n ; If the number set bits and the number of unset bits is equal ; Driver code
import java . util . * ; class GFG { static int TOTAL_BITS = 32 ; static boolean isPossible ( int n ) { int cnt = Integer . bitCount ( n ) ; if ( cnt == TOTAL_BITS / 2 ) return true ; return false ; } static public void main ( String [ ] arr ) { int n = 524280 ; if ( isPossible ( n ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }