[Python3] range sum with two pointers O(M+N)
Algo\nDefine two pointers i and ii to point to nums1 and nums2 respectively. Then, we move the pointer which points to smaller value and update its range sum. I
Algo\nDefine two pointers `i` and `ii` to point to `nums1` and `nums2` respectively. Then, we move the pointer which points to smaller value and update its range sum. If we encounter common value, we add the larger of the two range sum to `ans` and add the common value to `ans` as well. \n\nAt last, we add the larger of the range sum to `ans` one last time. \n\n`O(M+N)` time | `O(1)` space \n\n```\nclass Solution:\n    def maxSum(self, nums1: List[int], nums2: List[int]) -> int:\n        ans = i = ii = s = ss = 0\n        while i < len(nums1) and ii < len(nums2): \n            #update range sum & move pointer \n            if nums1[i] < nums2[ii]: \n                s += nums1[i] \n                i += 1\n            elif nums1[i] > nums2[ii]:\n                ss += nums2[ii]\n                ii += 1\n            #add larger range sum to ans\n            #add common value & move pointers\n            else: \n                ans += max(s, ss) + nums1[i]\n                s = ss = 0\n                i, ii = i+1, ii+1\n        #complete the range sum & update ans \n        ans += max(s + sum(nums1[i:]), ss + sum(nums2[ii:])) \n        return ans % 1_000_000_007\n```
['Python3']