Find the possible permutation of the bits of N | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int TOTAL_BITS = 32 ; bool isPossible ( int n ) { int cnt = __builtin_popcount ( n ) ; if ( cnt == TOTAL_BITS / 2 ) return true ; return false ; } int main ( ) { int n = 524280 ; if ( isPossible ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }