human
Longest common subarray in the given two arrays | Function to find the maximum length of equal subarray.
Auxiliary dp [ ] [ ] array.
Updating the dp [ ] [ ] table in Bottom Up approach.
If A [ i ] is equal to B [ i ] then dp [ j ] [ i ] = dp [ j + 1 ] [ i + 1 ] + 1.
Find maximum of all the values in dp [ ] [ ] array to get the maximum length.
Update the length.
Return the maximum length.
Driver Code.
Function call to find maximum length of subarray"
How can the above be solved in Python?
assistant
#Here is code to longest common subarray in the given two arrays and the other steps required.
 def FindMaxLength ( A , B ) :
	n = len ( A )
	m = len ( B )
	dp = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
	for i in range ( n - 1 , - 1 , - 1 ) :
		for j in range ( m - 1 , - 1 , - 1 ) :
			if A [ i ] == B [ j ] :
				dp [ j ] [ i ] = dp [ j + 1 ] [ i + 1 ] + 1
	maxm = 0
	for i in dp :
		for j in i :
			maxm = max ( maxm , j )
	return maxm
if __name__ == ' _ _ main _ _ ' :
	A = [ 1 , 2 , 8 , 2 , 1 ]
	B = [ 8 , 2 , 1 , 4 , 7 ]
	print ( FindMaxLength ( A , B ) )