Java | Simple Greedy Solution | Time: O(n) | Space: O(1)
\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        int MOD = (int) Math.pow(10,9) + 7;\n        int p1 = 0, p2 = 0;\n        long s1
```\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        int MOD = (int) Math.pow(10,9) + 7;\n        int p1 = 0, p2 = 0;\n        long s1 = 0, s2 = 0;\n        long maxScore = 0;\n        \n        while(p1 < nums1.length && p2 < nums2.length) {\n            if(nums1[p1] < nums2[p2]) {\n                s1 += nums1[p1];\n                p1++;\n            }\n            else if(nums1[p1] > nums2[p2]) {\n                s2 += nums2[p2];\n                p2++;\n            }\n            else {\n                maxScore += Math.max(s1, s2) + nums1[p1];\n                maxScore %= MOD;\n                s1 = s2 = 0;\n                p1++;\n                p2++;\n            }\n        }\n        \n        while(p1 < nums1.length) s1 += nums1[p1++];\n        while(p2 < nums2.length) s2 += nums2[p2++];\n        \n        maxScore += Math.max(s1, s2);\n        maxScore %= MOD;\n        \n        return (int) maxScore;\n    }\n}\n```
['Java']