C++ two pointer dp solution
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int maxSum(vector<int>& nums1, vector<int>& nums2) {
        int mod = 1e9+7;
        int n = max(nums1.size(), nums2.size());
        vector<vector<long long int>> dp(n, vector<long long int>(2,0)); 
        int i=0,j=0;
        int n1 = nums1.size(), n2 = nums2.size();
        while(i<n1 || j<n2){
            if(j>=n2 || (i<n1 && nums1[i] < nums2[j] )){
                dp[i][0] = nums1[i] + (i>0? dp[i-1][0]:0);
                i++;
            }            
            else if(i>=n1 || (j<n2 && nums2[j]<nums1[i])){
                dp[j][1] = nums2[j] + (j>0? dp[j-1][1]:0);
                j++;
            }
            else if(i<n1 && j<n2 && nums1[i] == nums2[j]){
                dp[i][0] = nums1[i] + (i>0? dp[i-1][0]:0);
                dp[j][1] = nums2[j] + (j>0? dp[j-1][1]:0);

                dp[i][0] = dp[j][1] = max(dp[i][0], dp[j][1]);

                i++;
                j++;

            }
        }

        return max(dp[n1-1][0], dp[n2-1][1]) % mod;
    }
};
```
['C++']