[Javascript] DP problem O(M+N)
```\nvar maxSum = function(nums1, nums2) {\n    let i = 0, j = 0;\n    let res1 = 0, res2 = 0;\n    const MAX = 10**9 + 7;\n    \n    while (i < nums1.length &&
```\nvar maxSum = function(nums1, nums2) {\n    let i = 0, j = 0;\n    let res1 = 0, res2 = 0;\n    const MAX = 10**9 + 7;\n    \n    while (i < nums1.length && j < nums2.length) {\n        if (nums1[i] == nums2[j]) {\n            const max = Math.max(res1, res2);\n            res1 = max + nums1[i++];\n            res2 = max + nums2[j++];\n        } else if (nums1[i] < nums2[j]) {\n            res1 += nums1[i++];\n        } else {\n            res2 += nums2[j++];\n        }\n    }\n    \n    while (i < nums1.length) {\n        res1 += nums1[i++];\n    }\n    \n    while (j < nums2.length) {\n        res2 += nums2[j++];\n    }\n    \n    return Math.max(res1, res2) % MAX;\n};
['JavaScript']