js dfs solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```javascript []\n/**\n * @param {number[]} nums1\n * @param {number[]} nums2\n * @return {number}\n */\nvar maxSum = function (nums1, nums2) {\n    const n = nums1.length, m = nums2.length, mod = Math.pow(10, 9) + 7\n    const hash = {}, hash1 = {}\n    for (let i = 0; i < n; i++) {\n        hash[nums1[i]] = i\n    }\n    for (let i = 0; i < m; i++) {\n        if (hash[nums2[i]]!==undefined) {\n            hash1[nums2[i]] = [hash[nums2[i]], i]\n        }\n    }\n    const memo1 = new Array(n).fill(-1), memo2 = new Array(m).fill(-1)\n    const dfs = (cur, x) => {\n        if (cur < 0) {\n            return 0\n        }\n        if (!x) {\n            if (memo1[cur] !== -1) {\n                return memo1[cur]\n            }\n            if (hash1[nums1[cur]]) {\n                memo1[cur] = Math.max(dfs(hash1[nums1[cur]][0] - 1, 0), dfs(hash1[nums1[cur]][1] - 1, 1)) + nums1[cur]\n            } else {\n                memo1[cur] = dfs(cur - 1, x) + nums1[cur] \n            }\n            return memo1[cur]\n        } else {\n            if (memo2[cur] !== -1) {\n                return memo2[cur]\n            }\n            if (hash1[nums2[cur]]) {\n                memo2[cur] = Math.max(dfs(hash1[nums2[cur]][0] - 1, 0), dfs(hash1[nums2[cur]][1] - 1, 1)) + nums2[cur]\n            } else {\n                memo2[cur] = (dfs(cur - 1, x) + nums2[cur])\n            }\n            return memo2[cur]\n        }\n    }\n    const x = Math.max(dfs(n - 1, false), dfs(m - 1, true))\n    return x % mod\n};\n\n```
['Dynamic Programming', 'Recursion', 'JavaScript']