JavaScript memorized search
Intuition\nIt is a typical dynamic programming problem.\n# Approach\nFor simplicity of coding, we use memorized search (recursion)\n# Complexity\n- Time complex
# Intuition\nIt is a typical dynamic programming problem.\n# Approach\nFor simplicity of coding, we use memorized search (recursion)\n# Complexity\n- Time complexity:\nO(n ** 2)\n- Space complexity:\nO(n ** 2)\n# Code\n```\n/**\n * @param {number[]} nums\n * @return {number}\n */\nvar maxOperations = function(nums) {\n    const len = nums.length\n    function toKey(...args) {\n        return args.join(\'|\')\n    }\n    const map = new Map()\n    function solve(i, j, sum) {\n        if (j - i < 1)  return 0\n        const key = toKey(i, j, sum)\n        if (map.has(key))   return map.get(key)\n\n        let result = 0\n        const a = nums[i], b = nums[i + 1]\n        if (a + b === sum)\n            result = Math.max(result, 1 + solve(i + 2, j, sum))\n        const c = nums[j], d = nums[j - 1]\n        if (c + d === sum)\n            result = Math.max(result, 1 + solve(i, j - 2, sum))\n        if (a + c === sum)\n            result = Math.max(result, 1 + solve(i + 1, j - 1, sum))\n\n        map.set(key, result)\n        return result\n    }\n\n\n    const a = nums[0], b = nums[1]\n    const c = nums[len - 1], d = nums[len - 2]\n    const resultX = 1 + solve(2, len - 1, a + b)\n    const resultY = 1 + solve(0, len - 3, c + d)\n    const resultZ = 1 + solve(1, len - 2, a + c)\n    \n\n    const result = Math.max(resultX, resultY, resultZ)\n    return result\n};\n```
['JavaScript']