C++ | Pure Recursion | explained with Intuition | 80ms | faster than 98.68%
----------------------------------------------Intuition:----------------------------------------\n\nI have to take all elements from array while i didn\'t find 
----------------------------------------------**Intuition:**----------------------------------------\n\nI have to take **all elements** from array while i **didn\'t find same element in another array**.\nbecause i can **move to another array if and only if there is same element in both.**\n\nso if i suppose element at **index \'i\' and \'j\' are present in another array** and elements between \'i\' and \'j\' are not present then i will consider **elements from \'i+1\' to \'j\' as single block** and i have to find **max sum using this array of blocks**.\n\n\n\n---------------------------------------------**Approch:**--------------------------------------------\n1. i will count **sum of every block** and store that in another vector. I will do this for the both vector which are given.\n\n2. i have to find **max score using this new arrays**. and at every point i have **2 choices i can take element from array1 or array2**. but to get max score i will **take element which is larger.**\n\n```\nclass Solution {\nprivate:\n    int N = 1000000007;\n    int getMaxSum(vector<long long>& arr1, vector<long long>& arr2, int n){\n        if(n == 0)\n            return 0;\n        \n        long long sum = getMaxSum(arr1,arr2,n-1);\n        \n        // at this point i have 2 choice \n        // i can take element from arr1 or arr2 and i will take larger element from it.\n        sum = (sum + max(arr1[n-1],arr2[n-1]))%N;\n        \n        return sum;\n    }\npublic:\n    int maxSum(vector<int>& nums1, vector<int>& nums2) {\n        vector<long long> arr1, arr2; // to store sum of blocks\n        long long sum1 = 0, sum2 = 0; // sum of current block\n        int n1 = nums1.size(), n2 = nums2.size();\n        int i = 0, j = 0;\n        \n        while(i < n1 && j < n2){\n            // if at this point element is present in both array then it is end of the block so add sum into arrays and reset the sum.\n            \n            // elese i will go to the next element in the array with smaller element to get next same element.\n            if(nums1[i] == nums2[j]){ \n                sum1 = (sum1+nums1[i]);\n                sum2 = (sum2+nums2[j]);\n                \n                arr1.push_back(sum1);\n                arr2.push_back(sum2);\n                sum1 = sum2 = 0;\n                \n                i++,j++;\n            }else if(nums1[i] < nums2[j]){\n                sum1 = (sum1+nums1[i]);\n                i++;\n            }else{\n                sum2 = (sum2+nums2[j]);\n                j++;\n            }\n        }\n        while(i < n1){\n            sum1 = (sum1+nums1[i]);\n            i++;\n        }\n        while(j < n2){\n            sum2 = (sum2+nums2[j]);\n            j++;\n        }\n        arr1.push_back(sum1);\n        arr2.push_back(sum2);\n        \n        return getMaxSum(arr1,arr2,arr1.size()); // to get max score.\n    }\n};\n\n```\n
['Recursion', 'C']