simple code
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```\nclass Solution {\n    int[][][] arr;\n    int sum1;\n    int sum2;\n    int sum3;\n    public int maxOperations(int[] nums) {\n        arr=new int[nums.length][nums.length][3];\n        int sum1=nums[0]+nums[1];\n        int sum2=nums[nums.length-1]+nums[nums.length-2];\n        int sum3=nums[0]+nums[nums.length-1];\n        for(int i=0;i<arr.length;i++)\n        {\n            for(int j=0;j<arr[0].length;j++)\n            {\n                for(int k=0;k<3;k++)\n                {\n                    arr[i][j][k]=-1;\n                }\n            }\n        }\n        int temp1= 1+ope(nums,2,nums.length-1,nums[0]+nums[1]);\n        int temp2= 1+ope(nums,0,nums.length-3,nums[nums.length-1]+nums[nums.length-2]);\n        int temp3= 1+ope(nums,1,nums.length-2,nums[0]+nums[nums.length-1]);\n        \n        return Math.max(temp1,Math.max(temp2,temp3));\n    }\n\n    int ope(int[] nums,int start,int end,int sum)\n    {   int res=0;\n      \n        if(start==end || start<0 || start>=nums.length || end<0 || end>=nums.length)\n        return 0;\n        \n        int val=0;\n        if(sum==sum1)\n        val=0;\n        else if(sum==sum2)\n        val=1;\n        else if(sum==sum3)\n        val=3;\n\n        if(arr[start][end][val] != -1)\n        return arr[start][end][val];\n\n        if((end-start >= 1) && (nums[start]+nums[start+1]) == sum)\n        {\n            res=Math.max(res,1+ope(nums,start+2,end,sum));\n        }\n\n         if((end-start >= 1) && (nums[end]+nums[end-1]) == sum)\n        {\n            res=Math.max(res,1+ope(nums,start,end-2,sum));\n        }\n\n        if((end-start >= 1) && (nums[start]+nums[end]) == sum)\n        {\n            res=Math.max(res,1+ope(nums,start+1,end-1,sum));\n        }\n\n        return arr[start][end][val]= res;\n    }\n\n}    \n\n\n\n```
['Java']