Java Solution
\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        long result = 0, sum1 = 0, sum2 = 0;\n        int i = 0, j = 0, m = 1_000_000_007
```\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        long result = 0, sum1 = 0, sum2 = 0;\n        int i = 0, j = 0, m = 1_000_000_007;\n        while(i < nums1.length || j < nums2.length) {\n            if(i == nums1.length)\n                sum2 += nums2[j++];\n            else if(j == nums2.length)\n                sum1 += nums1[i++];\n            else if(nums1[i] < nums2[j] )\n                sum1 += nums1[i++];\n            else if(nums2[j] < nums1[i] )\n                 sum2 += nums2[j++];\n            else{\n                result = (result + Math.max(sum1 + nums1[i++], sum2 + nums2[j++]) % m) % m;\n                sum1 = 0; sum2 = 0;\n            }\n        }\n        \n        return (int) (result + Math.max(sum1, sum2) % m) % m;\n    }\n}\n```
[]