human
What is a code to maximum subarray product modulo M and the other steps required given the following:
Maximum subarray product modulo M | Function to find maximum subarray product modulo M and minimum length of the subarray.
Stores maximum subarray product modulo M and minimum length of the subarray.
Stores the minimum length of subarray having maximum product.
Traverse the array.
Stores the product of a subarray.
Calculate Subarray whose start index is i.
Multiply product by arr [ i ].
If product greater than ans.
Update ans.
Update length.
Print maximum subarray product mod M.
Print minimum length of subarray having maximum product.
Drivers Code"
How can the above be solved in Python?
assistant
#Here is code to maximum subarray product modulo M and the other steps required.
 def maxModProdSubarr ( arr , n , M ) :
	ans = 0
	length = n
	for i in range ( n ) :
		product = 1
		for j in range ( i , n , 1 ) :
			product = ( product * arr [ i ] ) % M
			if ( product > ans ) :
				ans = product
				if ( length > j - i + 1 ) :
					length = j - i + 1
	print ( " Maximum ▁ subarray ▁ product ▁ is " , ans )
	print ( " Minimum ▁ length ▁ of ▁ the ▁ maximum ▁ product ▁ subarray ▁ is " , length )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 3 , 4 , 2 ]
	N = len ( arr )
	M = 5
	maxModProdSubarr ( arr , N , M )