Java solution using recursion with memoization (beats 98%)
Vote up if you like it . \n\n# Code\n\nclass Solution {\n\n    public boolean areAllElementsSame(int[] array) {\n        // Compare each element with the first 
# Vote up if you like it . \n\n# Code\n```\nclass Solution {\n\n    public boolean areAllElementsSame(int[] array) {\n        // Compare each element with the first element\n        int firstElement = array[0];\n        for (int i = 1; i < array.length; i++) {\n            if (array[i] != firstElement) {\n                return false; // If any element is different, return false\n            }\n        }\n\n        return true; // If all elements are the same, return true\n    }\n\n    public static int sol(int[] nums, int i, int j, int score, int[][] memo) {\n        // Base case\n        if (i >= j)\n            return 0;\n\n        // If the result is already computed, return it from the memoization table\n        if (memo[i][j] != -1)\n            return memo[i][j];\n\n        int option1 = 0, option2 = 0, option3 = 0;\n\n        // Calculate scores for three options\n        int score1 = nums[i] + nums[j];\n        int score2 = nums[i] + nums[i + 1];\n        int score3 = nums[j - 1] + nums[j];\n\n        // Calculate options based on score condition\n        if (score1 == score || score == -1) {\n            option1 = 1 + sol(nums, i + 1, j - 1, score1,memo);\n        }\n        if (score2 == score || score == -1) {\n            option2 = 1 + sol(nums, i + 2, j, score2,memo);\n        }\n        if (score3 == score || score == -1) {\n            option3 = 1 + sol(nums, i, j - 2, score3,memo);\n        }\n\n        // Update memoization table with the maximum of the three options\n        memo[i][j] = Math.max(option1, Math.max(option2, option3));\n        return memo[i][j];\n    }\n\n    public int maxOperations(int[] nums) {\n        int n = nums.length;\n        //check if all the elements of the array is same if yes just return the half the number of element in the array\n        if (areAllElementsSame(nums)) return n / 2;\n        // Create memoization table\n        int[][] memo = new int[n][n]; // memo[i][j] stores the maximum number of operations from index i to j\n                                      \n\n        // Initialize memoization table with -1\n        for (int[] row : memo) {\n            Arrays.fill(row, -1);\n        }\n\n        // Call the recursive function with memoization\n        return sol(nums, 0, n - 1, -1, memo);\n    }\n}\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']