Best Path Across Two Lists
first and second are both sorted in strictly increasing order. A path starts at the first item of either list and walks to the right, to the end of the list it is on. Whenever it stands on a number that also appears in the other list, it may switch over to that number in the other list and walk on from there.
The score of a path is the sum of the numbers it visits; a number where the path switches is counted once. Return the largest score.
Example 1
Start on the second list with 3, switch at 4 to pick up 20, and switch back at 30 to pick up 31: 3 + 4 + 20 + 30 + 31 = 88.
Example 2
The lists share no number, so the path stays on one list. The second list alone gives 10.
Constraints
1 <= len(first), len(second) <= 2001 <= first[i], second[i] <= 10**7- both lists are strictly increasing
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.