human
Check if two binary strings can be made equal by swapping 1 s occurring before 0 s | Function to check if it is possible to make two binary strings equal by given operations.
Stores count of 1 ' s ▁ and ▁ 0' s of the string str1.
Stores count of 1 ' s ▁ and ▁ 0' s of the string str2.
Stores current count of 1 's  presenty in the string str1.
Count the number of 1 ' s ▁ and ▁ 0' s present in the strings str1 and str2.
If the number of 1 ' s ▁ and ▁ 0' s are not same of the strings str1 and str2 then prnot possible.
Traversing through the strings str1 and str2.
If the str1 character not equals to str2 character.
Swaps 0 with 1 of the string str1.
Breaks the loop as the count of 1 's is zero. Hence, no swaps possible.
Swaps 1 with 0 in the string str1.
Prnot possible.
Given Strings.
Function Call"
Solution in Python:
 ... What is a code to check if two binary strings can be made equal by swapping 1 s occurring before 0 s and the other steps required?
assistant
#Here is code to check if two binary strings can be made equal by swapping 1 s occurring before 0 s and the other steps required.
 def isBinaryStringsEqual ( list1 , list2 ) :
	str1 = list ( list1 )
	str2 = list ( list2 )
	str1Zeros = 0
	str1Ones = 0
	str2Zeros = 0
	str2Ones = 0
	flag = 0
	curStr1Ones = 0
	for i in range ( len ( str1 ) ) :
		if ( str1 [ i ] == '1' ) :
			str1Ones += 1
		elif ( str1 [ i ] == '0' ) :
			str1Zeros += 1
		if ( str2 [ i ] == '1' ) :
			str2Ones += 1
		elif ( str2 [ i ] == '0' ) :
			str2Zeros += 1
	if ( str1Zeros != str2Zeros and str1Ones != str2Ones ) :
		print ( " Not ▁ Possible " )
	else :
		for i in range ( len ( str1 ) ) :
			if ( str1 [ i ] != str2 [ i ] ) :
				if ( str1 [ i ] == '0' and curStr1Ones > 0 ) :
					str1 [ i ] = '1'
					curStr1Ones -= 1
				if ( str1 [ i ] == '0' and curStr1Ones == 0 ) :
					flag += 1
					break
				if ( str1 [ i ] == '1' and str2 [ i ] == '0' ) :
					str1 [ i ] = '0'
					curStr1Ones += 1
		if ( flag == 0 ) :
			print ( " Possible " )
		else :
		print ( " Not ▁ Possible " )
str1 = "0110"
str2 = "0011"
isBinaryStringsEqual ( str1 , str2 )