java Solution
\nclass Solution {\n    int dp[][];\n    public int stoneGameVII(int[] stones) {\n        dp=new int[stones.length][stones.length];\n        for (int arr[]:dp)\
```\nclass Solution {\n    int dp[][];\n    public int stoneGameVII(int[] stones) {\n        dp=new int[stones.length][stones.length];\n        for (int arr[]:dp)\n        {\n            Arrays.fill(arr,-1);\n        }\n        int prefix[]=new int[stones.length];\n        prefix[0]=stones[0];\n        int n=stones.length;\n        for (int i=1;i<n;i++)\n        {\n            prefix[i]=prefix[i-1]+stones[i];\n        }\n        return helper(stones,0,stones.length-1,prefix);\n\n    }\n    int helper(int arr[],int i,int j,int prefix[])\n    {\n        if (i>=j)\n        {\n            return 0;\n        }\n        else\n        {\n            if (dp[i][j]!=-1)\n            {\n                return dp[i][j];\n            }\n            int res1=prefix[j]-prefix[i]-helper(arr,i+1,j,prefix);\n            int res2=prefix[j-1]-(((i-1>=0))?prefix[i-1]:0)-helper(arr,i,j-1,prefix);\n            return dp[i][j]=Math.max(res1,res2);\n        }\n    }\n}\n```
[]