human
Number of sub arrays with negative product | Function to return the count of subarrays with negative product.
Replace current element with 1 if it is positive else replace it with - 1 instead.
Take product with previous element to form the prefix product.
Count positive and negative elements in the prefix product array.
Return the required count of subarrays.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to number of sub arrays with negative product and the other steps required.
 def negProdSubArr ( arr , n ) :
	positive = 1
	negative = 0
	for i in range ( n ) :
		if ( arr [ i ] > 0 ) :
			arr [ i ] = 1
		else :
			arr [ i ] = - 1
		if ( i > 0 ) :
			arr [ i ] *= arr [ i - 1 ]
		if ( arr [ i ] == 1 ) :
			positive += 1
		else :
			negative += 1
	return ( positive * negative )
arr = [ 5 , - 4 , - 3 , 2 , - 5 ]
n = len ( arr )
print ( negProdSubArr ( arr , n ) )