Easy Choice Based DP
\n# Code\n\nclass Solution {\n    private int solve(int arr[], int left, int right, int score, Integer dp[][]) {\n        if (left >= right) return 0;\n        
\n# Code\n```\nclass Solution {\n    private int solve(int arr[], int left, int right, int score, Integer dp[][]) {\n        if (left >= right) return 0;\n        \n        if (dp[left][right] != null) return dp[left][right];\n        \n        int result = 0;\n        \n        //we have 3 choices\n        \n        if (arr[left] + arr[left + 1] == score)\n            //chose first two\n            result = 1 + solve(arr, left + 2, right, score, dp);\n        \n        if (arr[right] + arr[right - 1] == score)\n            //chose last two\n            result = Math.max(\n                result,\n                1 + solve(arr, left, right - 2, score, dp)\n            );\n        \n        if (arr[left] + arr[right] == score)\n            //chose left and right\n            result = Math.max(\n                result,\n                1 + solve(arr, left + 1, right - 1, score, dp)\n            );\n        \n        return dp[left][right] = result;\n    }\n    \n    public int maxOperations(int[] arr) {\n        int len = arr.length;\n        \n        //we have 3 different choise to start from, each choice will give different score to start with\n        int score1 = arr[0] + arr[1];               //chose first two\n        int score2 = arr[len - 1] + arr[len - 2];   //chose last two\n        int score3 = arr[0] + arr[len - 1];         //chose first and last\n        \n        \n        //return the result of choice which produces maximum result\n        int result =\n            solve(arr, 0, len - 1, score1, new Integer[len][len]);\n        \n        result = Math.max(\n            result,\n            solve(arr, 0, len - 1, score2, new Integer[len][len])\n        );\n        \n        result = Math.max(\n            result,\n            solve(arr, 0, len - 1, score3, new Integer[len][len])\n        );\n        \n        return result;\n    }\n}\n```
['Java']