Find the possible permutation of the bits of N | Python3 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
TOTAL_BITS = 32 ; NEW_LINE def isPossible ( n ) : NEW_LINE INDENT cnt = bin ( n ) . count ( '1' ) ; NEW_LINE if ( cnt == TOTAL_BITS // 2 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT return False ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT n = 524280 ; NEW_LINE if ( isPossible ( n ) ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT DEDENT