simple java dp solution | bottom-up | tabulation
\n# Code\n\nclass Solution {\n    public int maxOperations(int[] nums) {\n\n        int n = nums.length;\n        long[][][] dp = new long[n + 1][n + 1][4];\n  
\n# Code\n```\nclass Solution {\n    public int maxOperations(int[] nums) {\n\n        int n = nums.length;\n        long[][][] dp = new long[n + 1][n + 1][4];\n        \n        long max = 0;\n        for (int i = 0; i <= n; i++) {\n            for (int j = 0; j <= n; j++) {\n                dp[i][j][1] = 0;\n                dp[i][j][2] = 0;\n                dp[i][j][3] = 0;\n            }\n        }\n\n        long sum1 = nums[n - 1] + nums[n - 2];\n        long sum2 = nums[0] + nums[1];\n        long sum3 = nums[0] + nums[n - 1];\n\n        for (int i = 0; i < n - 1; i++) {\n            long sum = nums[i] + nums[i + 1];\n            if (sum == sum1) {\n                dp[i][i + 1][1] = 1;\n            }\n            if (sum == sum2) {\n                dp[i][i + 1][2] = 1;\n            }\n            if (sum == sum3) {\n                dp[i][i + 1][3] = 1;\n            }\n        }\n\n        for (int l = 3; l <= n; l++) {\n            int start = 0;\n            while (start <= n - l) {\n                int end = start + l - 1;\n\n                long sum = nums[start] + nums[start + 1];\n                if (sum == sum1) {\n                    dp[start][end][1] = Math.max(dp[start][end][1], 1 + dp[start + 2][end][1]);\n                }\n                if (sum == sum2) {\n                    dp[start][end][2] = Math.max(dp[start][end][2], 1 + dp[start + 2][end][2]);\n                }\n                if (sum == sum3) {\n                    dp[start][end][3] = Math.max(dp[start][end][3], 1 + dp[start + 2][end][3]);\n                }\n\n                sum = nums[end - 1] + nums[end];\n                if (sum == sum1) {\n                    dp[start][end][1] = Math.max(dp[start][end][1], 1 + dp[start][end - 2][1]);\n                }\n                if (sum == sum2) {\n                    dp[start][end][2] = Math.max(dp[start][end][2], 1 + dp[start][end - 2][2]);\n                }\n                if (sum == sum3) {\n                    dp[start][end][3] = Math.max(dp[start][end][3], 1 + dp[start][end - 2][3]);\n                }\n\n                sum = nums[start] + nums[end];\n                if (sum == sum1) {\n                    dp[start][end][1] = Math.max(dp[start][end][1], 1 + dp[start + 1][end - 1][1]);\n                }\n                if (sum == sum2) {\n                    dp[start][end][2] = Math.max(dp[start][end][2], 1 + dp[start + 1][end - 1][2]);\n                }\n                if (sum == sum3) {\n                    dp[start][end][3] = Math.max(dp[start][end][3], 1 + dp[start + 1][end - 1][3]);\n                }\n\n                start++;\n            }\n        }\n\n        long ans = Math.max(Math.max(dp[0][n - 1][1], dp[0][n - 1][2]), dp[0][n - 1][3]);\n        return (int) ans;\n    }\n}\n\n```
['Array', 'Dynamic Programming', 'Java']