human
Cost required to make all array elements equal to 1 | Function to calculate the cost required to make all array elements equal to 1.
Stores the total cost.
Traverse the array arr [ ].
If current element is 0.
Convert 0 to 1.
Add the cost.
Return the total cost.
Driver Code"
Solution in Python:
assistant
#Here is code to cost required to make all array elements equal to 1 and the other steps required.
 def findCost ( A , N ) :
	totalCost = 0
	for i in range ( N ) :
		if ( A [ i ] == 0 ) :
			A [ i ] = 1
			totalCost += i
	return totalCost
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 0 , 1 , 0 , 1 , 0 ]
	N = len ( arr )
	print ( findCost ( arr , N ) )