Given two arrays of integers, each in strictly increasing order, a path starts at the first element of either array and moves right. Whenever the current value also appears in the other array, the path may continue in either array from that shared value, and a shared value is counted once. The path ends when it runs off the end of its array. Return the largest possible sum of a path.
maxPathSum([2,4,5,8,10], [4,6,8,9]) is 30, from the path 2, 4, 6, 8, 10- Either array may be empty, and values may be negative
- Return the exact sum, with no modulus
- Aim for O(n + m) time and O(1) extra space