Java 2 pointer || Simple approach
The logic is pretty simple to find the sub-array sum between two common points of the given arrays and add the maximum of them to the result.\nIn case there are
The logic is pretty simple to find the sub-array sum between two common points of the given arrays and add the maximum of them to the result.\nIn case there are two or more consecutive common points, simply add one of the common points to the result.\n```\nclass Solution {\n    public int maxSum(int[] nums1, int[] nums2) {\n        long div=(long)(Math.pow(10,9))+7;\n        long ans=rec(nums1,nums2,nums1.length,nums2.length);\n        ans=ans%div;\n        return (int)(ans);\n    }\n    long max(long x, long y)  \n    { \n        return (x > y) ? x : y; \n    } \n  \n    \n    long rec(int ar1[], int ar2[], int m, int n)  \n    { \n        int i = 0, j = 0; \n\t\tlong result = 0, sum1 = 0, sum2 = 0; \n        while (i < m && j < n)  \n        { \n          if (ar1[i] < ar2[j]) \n                sum1 += ar1[i++]; \n            else if (ar1[i] > ar2[j]) \n                sum2 += ar2[j++]; \n\t\t   else\n\t\t\t\t{ \n                result += max(sum1, sum2); \n\t\t\t    sum1 = 0; \n                sum2 = 0; \n\t\t\t\twhile (i < m && j < n && ar1[i] == ar2[j])  \n                { \n                    result = result + ar1[i++]; \n                    j++; \n                } \n            } \n        } \n\t\twhile (i < m) \n            sum1 += ar1[i++]; \n        while (j < n)  \n            sum2 += ar2[j++]; \n\t\t result += max(sum1, sum2); \n\t\treturn result; \n    } \n}\n```
[]