human
Maximum Sum Path in Two Arrays | This function returns the sum of elements on maximum path from beginning to end.
initialize indexes for ar1 [ ] and ar2 [ ].
Initialize result and current sum through ar1 [ ] and ar2 [ ].
Below 3 loops are similar to merge in merge sort.
Add elements of ar1 [ ] to sum1.
Add elements of ar2 [ ] to sum2.
we reached a common point.
Take the maximum of two sums and add to result.
update sum1 and sum2 to be considered fresh for next elements.
update i and j to move to next element in each array.
Add remaining elements of ar1 [ ].
Add remaining elements of b [ ].
Add maximum of two sums of remaining elements.
Driver code.
Function call"
Solution in Python:
 Write me a code to maximum Sum Path in Two Arrays and the other steps required?
assistant
#Here is code to maximum Sum Path in Two Arrays and the other steps required.
 def maxPathSum ( ar1 , ar2 , m , n ) :
	i , j = 0 , 0
	result , sum1 , sum2 = 0 , 0 , 0
	while ( i < m and j < n ) :
		if ar1 [ i ] < ar2 [ j ] :
			sum1 += ar1 [ i ]
			i += 1
		elif ar1 [ i ] > ar2 [ j ] :
			sum2 += ar2 [ j ]
			j += 1
		else :
			result += max ( sum1 , sum2 ) + ar1 [ i ]
			sum1 = 0
			sum2 = 0
			i += 1
			j += 1
	while i < m :
		sum1 += ar1 [ i ]
		i += 1
	while j < n :
		sum2 += ar2 [ j ]
		j += 1
	result += max ( sum1 , sum2 )
	return result
ar1 = [ 2 , 3 , 7 , 10 , 12 , 15 , 30 , 34 ]
ar2 = [ 1 , 5 , 7 , 8 , 10 , 15 , 16 , 19 ]
m = len ( ar1 )
n = len ( ar2 )
print " Maximum ▁ sum ▁ path ▁ is " , maxPathSum ( ar1 , ar2 , m , n )