Detailed explanation, simple memoization using Java
Just think like a child. At every step there are 2 possibilities, \n\t1 .Picking the first stone.\n\t2. Picking the last stone.\n\nAt each step both of them wan
Just think like a child. At every step there are 2 possibilities, \n\t1 .Picking the first stone.\n\t2. Picking the last stone.\n\nAt each step both of them want to maximize the difference between their current score and the score that the other playes gets in the next step. This will be achieved by "maximizing the difference in the current score and the other player\'s score in the next step)\n\n**maximum(scoreOnRemovingFirstElement - score obtained on subsequent steps,**\n\t\t\t**scoreOnRemovingLastElement - score obtained on subsequent steps)**\n\n```\nclass Solution {\n    \n    int[][] dp = null;\n    \n    private int solve(int[] stones, int start, int end, int sum){\n        if(start>=end){\n            return 0;\n        }\n        if(dp[start][end] !=-1){\n            return dp[start][end];\n        }\n        \n        int scoreOnRemovingFirst = sum - stones[start];\n        int scoreOnRemovingLast = sum - stones[end];\n        \n        dp[start][end] = Math.max(scoreOnRemovingFirst - solve(stones, start+1, end, scoreOnRemovingFirst),\n                                 scoreOnRemovingLast - solve(stones, start, end-1, scoreOnRemovingLast));\n                                  \n        return dp[start][end];\n                                  \n    }\n    \n    public int stoneGameVII(int[] stones) {\n        int n = stones.length;\n        \n        dp = new int[n][n];\n        for(int i=0;i<n;i++){\n            Arrays.fill(dp[i],-1);\n        }\n        \n        int sum = 0;\n        for(int num: stones){\n            sum += num;\n        }\n        return solve(stones, 0, n-1, sum);\n        \n    }\n}
[]