Java HashMap O(n + m)
\n/*\n        Time Complexity: O(n + m)\n        Space Complexity: O(n + m)\n    */\n    public int maxSum(int[] nums1, int[] nums2) {\n        long mod = 10000
```\n/*\n        Time Complexity: O(n + m)\n        Space Complexity: O(n + m)\n    */\n    public int maxSum(int[] nums1, int[] nums2) {\n        long mod = 1000000007;\n        Map<Integer, Long> hm1 = new HashMap();\n        Map<Integer, Long> hm2 = new HashMap();\n        hm1.put(0, 0L);\n        long cum = 0;\n        long ans = 0;\n        for(int i: nums1){\n            cum += i;\n            hm1.put(i, cum);\n        }\n        hm2.put(0, 0L);\n        cum = 0;\n        for(int i: nums2){\n            cum += i;\n            hm2.put(i, cum);\n        }\n        int prev = 0;\n        for(int i: nums1){\n            if(hm2.containsKey(i)){\n                ans += Math.max(hm2.get(i) - hm2.get(prev) , hm1.get(i) - hm1.get(prev));\n                prev = i;\n            }\n        }\n        ans += Math.max(hm1.get(nums1[nums1.length-1]) - hm1.get(prev), hm2.get(nums2[nums2.length - 1]) - hm2.get(prev));\n        return (int)(ans % mod);\n    }\n```
[]