O(n) C++ Solution , Greedy Approach : )
\tint maxSum(vector& nums1, vector& nums2) {\n        long long int a=0,b=0;\n        long long int ans =0;\n        int i = 0, j = 0;\n        int n = nums1.si
\tint maxSum(vector<int>& nums1, vector<int>& nums2) {\n        long long int a=0,b=0;\n        long long int ans =0;\n        int i = 0, j = 0;\n        int n = nums1.size(), m = nums2.size();\n        while(i<n and j<m){\n            if(nums1[i] < nums2[j]){\n                a+=nums1[i];\n                i++;\n            }\n            else if(nums1[i] > nums2[j]){\n                b+=nums2[j];\n                j++;\n            }\n            else{\n                ans = ans+ max(a,b) + nums1[i];\n                a=0,b=0;i++;j++;\n            }\n        }\n        while(i<n) a+=nums1[i++];\n        while(j<m) b+=nums2[j++];\n        ans+= max(a,b);\n        ans%=1000000007;\n        return ans;\n    }
['Two Pointers', 'Dynamic Programming', 'C']