Based on MergeSort O(n)
based on the merge function of mergeSort. we keep a track of both the paths that we can take , once we encounter a similar number we update the result and make 
based on the merge function of mergeSort. we keep a track of both the paths that we can take , once we encounter a similar number we update the result and make the sum1 and sum2 0 again . dry run the code , it will help a lot . \n```\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        long sum1=0,sum2=0,res=0;\n        int i=0,j=0;\n        while(i<nums1.length && j<nums2.length){\n             if(nums1[i]<nums2[j]){\n                sum1+=nums1[i++];\n             }else if(nums1[i]>nums2[j]){\n                sum2+=nums2[j++];\n             }else{\n                long toAdd = Math.max(sum1,sum2);\n                res+= toAdd+nums1[i];\n                sum1=0;sum2=0;i++;j++;\n             }\n        }\n        while(i<nums1.length){\n            sum1+=nums1[i++];\n        }\n        while(j<nums2.length){\n            sum2+=nums2[j++];\n        }\n        long toAdd= Math.max(sum1,sum2);\n        res+= toAdd;\n        long mod  = (long)Math.pow(10,9)+7;\n        return (int)(res%mod);\n    }\n}\n```
['Two Pointers', 'Merge Sort', 'Java']