Python3. O(N) Time, O(1) space; Two pointers; explanation added
Logic is simple:\nLet\'s say that a place where nums1[i] = nums2[j] is checkpoint.\nThen result will be max prefix sum of two arrays + checkpoint + max sum post
Logic is simple:\nLet\'s say that a place where `nums1[i] = nums2[j]` is checkpoint.\nThen result will be max prefix sum of two arrays + checkpoint + max sum postfix of two arrays\nOr: `max(sum(nums1[0:i]), sum(nums2[0:j]) + checkpoint + max(sum(nums1[i + 1:]), sum(nums2[j + 1:]))` \n\nSo what we need to do is:\n1. Iterate through two arrays with calculating sum until we find checkpoint\n2. Add larger sum to result.\n3. Add checkpoint to result.\n4. Reset sums.\n5. Repeat.\n\n```python\nclass Solution:\n    def maxSum(self, nums1: List[int], nums2: List[int]) -> int:\n\t\tM, N = len(nums1), len(nums2)\n        sum1, sum2 = 0, 0\n        i, j = 0, 0\n        res = 0\n        while i < M and j < N:\n            if nums1[i] < nums2[j]:\n                sum1 += nums1[i]\n                i += 1\n            elif nums1[i] > nums2[j]:\n                sum2 += nums2[j]\n                j += 1\n            else:\n                res += max(sum1, sum2) + nums1[i]\n                i += 1\n                j += 1\n                sum1 = 0\n                sum2 = 0\n                \n        while i < M:\n            sum1 += nums1[i]\n            i += 1\n        while j < N:\n            sum2 += nums2[j]\n            j += 1\n        return (res + max(sum1, sum2)) % 1000000007\n```\n\nTime: O(N), where N is the total number of elements in arrays.\nSpace: O(1)
['Python']