java 85% beats
Intuition\nusing dynamic programming(recursive method)\n\n\n# Complexity\n- Time complexity:\no(n2)\n\n- Space complexity:\no(n2)\n\n# Code\n\nclass Solution {\
# Intuition\nusing dynamic programming(recursive method)\n\n\n# Complexity\n- Time complexity:\no(n2)\n\n- Space complexity:\no(n2)\n\n# Code\n```\nclass Solution {\n    public int maxOperations(int[] nums) {\n        int n=nums.length;\n        int[][] dp=new int[nums.length][nums.length];\n        for(int i=0;i<n;i++){\n            Arrays.fill(dp[i],-1);\n        }\n        int x=helper(nums,0,n-3,nums[n-1]+nums[n-2],dp);\n        \n        int y=helper(nums,1,n-2,nums[n-1]+nums[0],dp);\n        \n        int z=helper(nums,2,n-1,nums[0]+nums[1],dp);\n        return Math.max(x,Math.max(y,z))+1;\n    }\n    public int helper(int[] nums,int i,int j,int sum,int[][] dp){\n        if(i>=j){\n            return 0;\n        }\n        int x=0;\n        int y=0;\n        int z=0;\n        if(dp[i][j]!=-1){\n            return dp[i][j];\n        }\n        if(nums[i]+nums[j]==sum){\n            x=helper(nums,i+1,j-1,sum,dp)+1;\n        }\n        if(nums[i]+nums[i+1]==sum){\n            y=helper(nums,i+2,j,sum,dp)+1;\n        }\n        if(nums[j]+nums[j-1]==sum){\n            z=helper(nums,i,j-2,sum,dp)+1;\n        }\n        dp[i][j]=Math.max(x,Math.max(y,z));\n        return dp[i][j];\n    }\n}\n```
['Dynamic Programming', 'Recursion', 'Java']