Python O(m + n)  by DP [w/ Visualization]
Python sol by DP\n\n---\n\nScan from left to rigjt.\nIf two numbers are different, update accumulation to the list who has the smaller number.\nThen the updated
Python sol by DP\n\n---\n\nScan from left to rigjt.\nIf two numbers are different, update accumulation to the list who has the smaller number.\nThen the updated list moves to next number.\n\nIf two numbers are the same(i.e., common), update accumulation from the larger branch to both list #1 and list #2.\nThen both two lists move to their next numbers.\n\nKeep doing so until all numbers are visited.\n\nFinally, the maximum accumulation value is the answer.\n\nNote:\nRemember to take the module on return, which is defined by description.\n![image](https://assets.leetcode.com/users/images/79e46a8f-479c-4582-b92e-5703ef4ecc46_1596527071.858294.png)\n\n---\n\n**Demo**\n\n![image](https://assets.leetcode.com/users/images/0f871ed5-814b-4f39-913f-672764c0300a_1596526814.2644095.png)\n\n![image](https://assets.leetcode.com/users/images/03e83db4-a329-4789-ab46-e4794928fb76_1596527221.1831665.png)\n\n\n---\n\n**Implementation**:\n\n```\nclass Solution:\n    def maxSum(self, nums1: List[int], nums2: List[int]) -> int:\n        \n        size_1, size_2 = len(nums1), len(nums2)\n        \n        idx_1, idx_2 = 0, 0\n        \n        cur_acc_1, cur_acc_2 = 0, 0\n        \n        while idx_1 < size_1 or idx_2 < size_2:\n            \n            pre_acc_1, pre_acc_2 = cur_acc_1, cur_acc_2\n            \n            if (idx_1 < size_1 and idx_2 < size_2) and nums1[idx_1] == nums2[idx_2]:\n                \n                # now we have common number, select the larger branch\n                # then update accumulation of list 1 and list 2\n                accumulation = max(pre_acc_1, pre_acc_2) + nums1[idx_1] \n                cur_acc_1, cur_acc_2 = accumulation, accumulation\n                \n                idx_1, idx_2 = idx_1 + 1, idx_2 + 1\n                \n            elif idx_1 < size_1 and ((idx_2 == size_2) or (nums1[idx_1] < nums2[idx_2])):\n                \n                # list 2 meet the end or list 1 has smaller element\n                # update accumulation of list 1\n                cur_acc_1 = pre_acc_1 + nums1[idx_1] \n                idx_1 += 1\n                \n            elif idx_2 < size_2 and ((idx_1 == size_1) or (nums2[idx_2] < nums1[idx_1])):\n                \n                # list 1 meet the end or list 2 has smaller element\n                # update accumulation of list 2\n                cur_acc_2 = pre_acc_2 + nums2[idx_2] \n                idx_2 += 1\n                \n                \n        # remember to module constant before return answer\n        return max(cur_acc_1, cur_acc_2) % (10**9 + 7)\n```\n
['Dynamic Programming', 'Python', 'Python3']