simple linear  solution O(1) space
\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        long  long mod=1e9+7;\n        int n=nums2.size();\n        int m
```\nclass Solution {\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        long  long mod=1e9+7;\n        int n=nums2.size();\n        int m=nums1.size();\n        long long sum1=0,sum2=0;\n        long long ans=0;\n        int i=0,j=0;\n        while(i<m && j<n){\n            if(nums1[i]>nums2[j]){\n                sum2+=nums2[j++];\n            }\n            else if(nums1[i]<nums2[j]){\n                 sum1+=nums1[i++];\n            }\n            else{\n               sum2+=nums2[j++];\n                sum1+=nums1[i++];\n                ans=(ans+max(sum1,sum2))%mod;\n                sum1=0,sum2=0;\n            }\n           \n        }\n        while(i<m){\n            sum1+=nums1[i++];\n           \n        }\n        while(j<n){\n             sum2+=nums2[j++];\n            \n        }\n        ans=(ans+max(sum1,sum2))%mod;\n        return ans;\n    }\n};\n```
[]