human
What is a code to longest subarray of an array which is a subsequence in another array and the other steps required given the following:
Longest subarray of an array which is a subsequence in another array | Function to find the length of the longest subarray in arr1 which is a subsequence in arr2.
Length of the array arr1.
Length of the array arr2.
Length of the required longest subarray.
Initialize DParray.
Traverse array arr1.
Traverse array arr2.
arr1 [ i - 1 ] contributes to the length of the subarray.
Otherwise.
Find the maximum value present in DP.
Return the result.
Driver Code.
Function call to find the length of the longest required subarray"
How can the above be solved in Python?
assistant
#Here is code to longest subarray of an array which is a subsequence in another array and the other steps required.
 def LongSubarrSeq ( arr1 , arr2 ) :
	M = len ( arr1 ) ;
	N = len ( arr2 ) ;
	maxL = 0 ;
	DP = [ [ 0 for i in range ( N + 1 ) ] for j in range ( M + 1 ) ] ;
	for i in range ( 1 , M + 1 ) :
		for j in range ( 1 , N + 1 ) :
			if ( arr1 [ i - 1 ] == arr2 [ j - 1 ] ) :
				DP [ i ] [ j ] = 1 + DP [ i - 1 ] [ j - 1 ] ;
			else :
				DP [ i ] [ j ] = DP [ i ] [ j - 1 ] ;
	for i in range ( M + 1 ) :
		for j in range ( 1 , N + 1 ) :
			maxL = max ( maxL , DP [ i ] [ j ] ) ;
	return maxL ;
if __name__ == ' _ _ main _ _ ' :
	arr1 = [ 4 , 2 , 3 , 1 , 5 , 6 ] ;
	arr2 = [ 3 , 1 , 4 , 6 , 5 , 2 ] ;
	print ( LongSubarrSeq ( arr1 , arr2 ) ) ;