human
Maximum number of uncrossed lines between two given arrays | Function to count maximum number of uncrossed lines between the two given arrays.
Stores the length of lcs obtained upto every index.
Iterate over first array.
Iterate over second array.
Update value in dp table.
If both characters are equal.
Update the length of lcs.
If both characters are not equal.
Update the table.
Return the answer.
Driver Code.
Given array A [ ] and B [ ].
Function Call"
Solution in Python:
assistant
#Here is code to maximum number of uncrossed lines between two given arrays and the other steps required.
 def uncrossedLines ( a , b , n , m ) :
	dp = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
	for i in range ( n + 1 ) :
		for j in range ( m + 1 ) :
			if ( i == 0 or j == 0 ) :
				dp [ i ] [ j ] = 0
			elif ( a [ i - 1 ] == b [ j - 1 ] ) :
				dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]
			else :
				dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )
	return dp [ n ] [ m ]
if __name__ == " _ _ main _ _ " :
	A = [ 3 , 9 , 2 ]
	B = [ 3 , 2 , 9 ]
	N = len ( A )
	M = len ( B )
	print ( uncrossedLines ( A , B , N , M ) )