maximum-number-of-operations-with-the-same-score-ii - Java Solution
\njava []\nclass Solution {\n    public int maxOperations(int[] nums) {\n        //With Memoization : start [Beats 50%] [136ms]\n        return withMemoization(
\n```java []\nclass Solution {\n    public int maxOperations(int[] nums) {\n        //With Memoization : start [Beats 50%] [136ms]\n        return withMemoization(nums);\n        //With Memoization : end\n    }\n    \n    public int withMemoization(int[] nums){\n        int n = nums.length;\n        int i = 0;\n        int j = n-1;\n        int sum1 = nums[i] + nums[i+1]; \n        int sum2 = nums[i] + nums[j];\n        int sum3 = nums[j-1] + nums[j];\n\n        Integer[][] memo = new Integer[n+1][n+1];\n        int ans = withMemo(i,j,nums,sum1,memo);\n\n        memo = new Integer[n+1][n+1];\n        ans = Math.max(ans, withMemo(i,j,nums,sum2,memo));\n\n        memo = new Integer[n+1][n+1];\n        ans = Math.max(ans, withMemo(i,j,nums,sum3,memo));\n\n        return ans;\n    }\n\n    public int withMemo(int i,int j,int[] arr,int sum,Integer[][] memo){\n        if(j <= i) return 0;\n        if(memo[i][j] != null) return memo[i][j];\n\n        int ans = 0;\n        if(arr[i] + arr[j] == sum){\n            ans = Math.max(ans,1 + withMemo(i+1,j-1,arr,sum,memo));\n        }\n\n        if(arr[i] + arr[i+1] == sum){\n            ans = Math.max(ans,1 + withMemo(i+2,j,arr,sum,memo));\n        }\n\n        if(arr[j-1] + arr[j] == sum){\n            ans = Math.max(ans,1 + withMemo(i,j-2,arr,sum,memo));\n        }\n\n        memo[i][j] = ans;\n        return ans;\n    }\n}\n```
['Array', 'Dynamic Programming', 'Memoization', 'Java']