O(n) Time | O(1) Space | Simple C++
```\nint maxSum(vector& nums1, vector& nums2) {\n        long long ans=0;\n        long long mod= 1000000007;\n        int n1=nums1.size(),n2=nums2.size();\n   
```\nint maxSum(vector<int>& nums1, vector<int>& nums2) {\n        long long ans=0;\n        long long mod= 1000000007;\n        int n1=nums1.size(),n2=nums2.size();\n        \n        long long up=0,dn=0;\n        int i=0,j=0;\n        while(i<n1 && j<n2){\n            if(nums1[i]==nums2[j]){\n                ans+= max(up,dn)+ nums1[i];\n                up=0,dn=0;\n                i++,j++;\n            }\n            else if(nums1[i]>nums2[j]){\n                dn+= nums2[j];\n                j++;\n            }\n            else{\n                up+= nums1[i];\n                i++;\n            }\n        }\n        while(i<n1) up+=nums1[i++];\n        while(j<n2) dn+=nums2[j++];\n        return (max(up,dn)+ans)%mod;\n    }\n\t
['Dynamic Programming', 'C', 'C++']