human
Give me a code to length of maximum product subarray and the other steps required given the following:
Length of maximum product subarray | function that returns the maximum length subarray having non zero product.
zeroindex list to store indexex of zero.
if zeroindex list is empty then Maxlength is as size of array.
if zeroindex list is not empty.
first zero is on index 2 that means two numbers positive , before index 2 so as their product is positive to.
checking for other indexex.
if the difference is greater than maxlen then maxlen is updated.
to check the length of remaining array after last zeroindex.
Driver Code"
Solution in Python:
assistant
#Here is code to length of maximum product subarray and the other steps required.
 def Maxlength ( arr , N ) :
	zeroindex = [ ]
	for i in range ( N ) :
		if ( arr [ i ] == 0 ) :
			zeroindex . append ( i )
	if ( len ( zeroindex ) == 0 ) :
		maxlen = N
	else :
		maxlen = zeroindex [ 0 ]
		for i in range ( 0 , len ( zeroindex ) - 1 ) :
			if ( zeroindex [ i + 1 ] \ - zeroindex [ i ] - 1 \ > maxlen ) :
				maxlen = zeroindex [ i + 1 ] - zeroindex [ i ] - 1
		if ( N - zeroindex [ len ( zeroindex ) - 1 ] \ - 1 > maxlen ) :
			maxlen = N - zeroindex [ len ( zeroindex ) - 1 ] - 1
	print ( maxlen )
if __name__ == " _ _ main _ _ " :
	N = 9
	arr = [ 7 , 1 , 0 , 1 , 2 , 0 , 9 , 2 , 1 ]
	Maxlength ( arr , N )