human
Binary representation of next greater number with same number of 1 ' s ▁ and ▁ 0' s | Function to find the next greater number with same number of 1 ' s ▁ and ▁ 0' s.
locate first ' i ' from end such that bnum [ i ] == '0' and bnum [ i + 1 ] == '1' swap these value and break.
if no swapping performed.
Since we want the smallest next value , shift all 1 ' s ▁ at ▁ the ▁ end ▁ in ▁ the ▁ binary ▁ ▁ substring ▁ starting ▁ from ▁ index ▁ ' i + 2.
special case while swapping if '0' occurs then break.
required next greater number.
Driver code"
Solution in Python:

Can you provide a code to binary representation of next greater number with same number of 1 ' s ▁ and ▁ 0' s and the other steps required?
assistant
#Here is code to binary representation of next greater number with same number of 1 ' s ▁ and ▁ 0' s and the other steps required.
 def nextGreaterWithSameDigits ( bnum ) :
	l = len ( bnum )
	bnum = list ( bnum )
	for i in range ( l - 2 , 0 , - 1 ) :
		if ( bnum [ i ] == '0' and bnum [ i + 1 ] == '1' ) :
			ch = bnum [ i ]
			bnum [ i ] = bnum [ i + 1 ]
			bnum [ i + 1 ] = ch
			break
	if ( i == 0 ) :
		return " no ▁ greater ▁ number "
'
	j = i + 2
	k = l - 1
	while ( j < k ) :
		if ( bnum [ j ] == '1' and bnum [ k ] == '0' ) :
			ch = bnum [ j ]
			bnum [ j ] = bnum [ k ]
			bnum [ k ] = ch
			j += 1
			k -= 1
		elif ( bnum [ i ] == '0' ) :
			break
		else :
			j += 1
	return bnum
bnum = "10010"
print ( " Binary ▁ representation ▁ of ▁ next ▁ greater ▁ number ▁ = ▁ " , * nextGreaterWithSameDigits ( bnum ) , sep = " " )