human
Give me a code to minimum adjacent swaps required to Sort Binary array and the other steps required given the following:
Minimum adjacent swaps required to Sort Binary array | Function to find minimum swaps to sort an array of 0 s and 1 s ..
Array to store count of zeroes.
Count number of zeroes on right side of every one ..
Count total number of swaps by adding number of zeroes on right side of every one ..
Driver code"
Solution in Python:
assistant
#Here is code to minimum adjacent swaps required to Sort Binary array and the other steps required.
 def findMinSwaps ( arr , n ) :
	noOfZeroes = [ 0 ] * n
	count = 0
	noOfZeroes [ n - 1 ] = 1 - arr [ n - 1 ]
	for i in range ( n - 2 , - 1 , - 1 ) :
		noOfZeroes [ i ] = noOfZeroes [ i + 1 ]
		if ( arr [ i ] == 0 ) :
			noOfZeroes [ i ] = noOfZeroes [ i ] + 1
	for i in range ( 0 , n ) :
		if ( arr [ i ] == 1 ) :
			count = count + noOfZeroes [ i ]
	return count
arr = [ 0 , 0 , 1 , 0 , 1 , 0 , 1 , 1 ]
n = len ( arr )
print ( findMinSwaps ( arr , n ) )