Beginner + Advanced Two Pointers Solutions!
Beginner SolutionAdvanced Solution
# Beginner Solution
```python3 []
class Solution:
    def maxSum(self, nums1: List[int], nums2: List[int]) -> int:
        ans = i = j = 0
        curr1, curr2 = nums1[0], nums2[0]
        m, n = len(nums1), len(nums2)
        while i < m or j < n:
            if i == m:
                curr2 += sum(nums2[j+1:n])
                j = n
                break
            elif j == n:
                curr1 += sum(nums1[i+1:m])
                i = m
                break
            if nums1[i] == nums2[j]:
                ans += max(curr1, curr2)
                i += 1
                j += 1
                curr1 = nums1[i] if i != m else 0
                curr2 = nums2[j] if j != n else 0
            elif nums1[i] < nums2[j]:
                i += 1
                curr1 += nums1[i] if i != m else 0
            elif nums1[i] > nums2[j]:
                j += 1
                curr2 += nums2[j] if j != n else 0
        return (ans + max(curr1, curr2)) % (10**9 + 7)
```

---

# Advanced Solution
```python3 []
class Solution:
    def maxSum(self, A: List[int], B: List[int]) -> int:
        i = j = a = b = 0
        n, m = len(A), len(B)
        while i < n or j < m:
            if i < n and (j == m or A[i] < B[j]):
                a += A[i]
                i += 1
            elif j < m and (i == n or A[i] > B[j]):
                b += B[j]
                j += 1
            else:
                a = b = max(a, b) + A[i]
                i += 1
                j += 1
        return max(a, b) % (10**9 + 7)
```




['Python3']