Easy solution based on Merge sort
\nclass Solution {\npublic:\n    int maxSum(vector<int>& arr1, vector<int>& arr2) {\n        long long i = 0, j = 0, n = arr1.size() , m= arr2.size() , mod = 1e
```\nclass Solution {\npublic:\n    int maxSum(vector<int>& arr1, vector<int>& arr2) {\n        long long i = 0, j = 0, n = arr1.size() , m= arr2.size() , mod = 1e9+7;\n        long long res = 0, sum1 = 0, sum2 = 0;\n        \n        // when arr1 value is less than the value of arr2 add into sum1 and vise versa\n        // when both arr1 and arr2 value is same add maximum of them into result and also add same value into result and reset sum1 and sum2\n        // by doing this we are ensuring that added value in result is always maximum till common value found\n        \n        while(i < n && j < m){\n            if(arr1[i] < arr2[j]) sum1 += arr1[i++];\n            else if(arr1[i] > arr2[j]) sum2 += arr2[j++];\n            else{\n                res += max(sum1,sum2);\n                sum1 = 0,sum2 = 0;\n                while(i < n && j < m && arr1[i] == arr2[j])\n                {\n                    res += arr1[i];\n                    i++;\n                    j++;\n                }\n            }\n        }\n        while(i < n) sum1 += arr1[i++];  // remaining element of any array\n        while(j < m) sum2 += arr2[j++];\n        res += max(sum1,sum2);\n        return (res + mod) % mod;\n    }\n};\n```
['C', 'Merge Sort']