O(N) Time, O(1) space, very simple c++ solution
\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        int n1 = nums1.size();\n        int n2 = nums2.size();\n        i
```\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        int n1 = nums1.size();\n        int n2 = nums2.size();\n        int ans=0, s1=0, s2=0;\n        int i=0, j=0;\n        while(i< n1 and j <n2)\n        {\n            if(nums1[i] < nums2[j])\n            {\n                s1 = s1+nums1[i];\n                i++;\n            }\n            else if(nums1[i] > nums2[j])\n            {\n                s2 += nums2[j];\n                j++;\n            }\n            else if(nums1[i] == nums2[j])\n            {\n                ans += max(s1, s2) + nums1[i];\n                s1=0; s2=0;\n                i++;j++;\n            }\n        }\n        while(j<n2)\n        {\n            s2=s2+nums2[j];\n            j++;\n        }\n        while(i<n1)\n        {\n            s1+=nums1[i];\n            i++;\n        }\n        ans = ans+max(s1, s2);\n        return ans%1000000007;\n    }\n};\n```\n
[]