C++ with logic explanation
Both players want to MAXIMISE difference. \nIt says B wants to minimize absolute difference wrt A, but if consider max() on negative numbers, the lower absolute
Both players want to MAXIMISE difference. \nIt says B wants to minimize absolute difference wrt A, but if consider max() on negative numbers, the lower absolute difference gets picked anyway. \n\nSince both players have the same objective (to maximize difference in score), whose chance it is does not matter.\n\nAssuming only the stones in (i,j) range are left.\nif we know the optimal difference for (i,j-1) range and (i+1,j)  range respectively, we can find out whether we should pick the ith stone or the jth stone.\n\nTo Calculate for any i to j interval, what will be the optimal stone to pick:\n    j==i  ->  pick ith stone\n    j==i+1 -> pick the smaller stone\n    j==i+2 -> pick between i and j based on max(sum(i+1,j) - diff(i+1,j) , sum(i,j-1) - diff(i,j-1))\n    where diff(i+1,j) is the optimal score difference when only stones in (i+1,j) range are left and both play optimally.  \n\tsum(i+1,j) are the points obtained on picking ith stone(sum of remaining stones).\n\nSo now build diff(i,j) using dynamic programming and then return diff(0,n-1) which will be the answer\n\n```\nclass Solution {\npublic:\n    /*\n\n    */\n    int stoneGameVII(vector<int>& stones) {\n        \n        int n = stones.size();\n        \n        int diff[n][n];\n        memset(diff,0,sizeof(diff));\n        \n        int sum[n][n];\n        for(int i=0;i<n;i++) sum[i][i] = stones[i];\n        \n        \n        // for(int i=0;i)\n        for(int l=2;l<=n;l++)\n        {\n            for(int i=0;i<=n-l;i++)\n            {\n                int j = i+l-1;\n                sum[i][j] = stones[j] + sum[i][j-1];\n            }\n        }\n        \n        for(int l=2;l<=n;l++)\n        {\n            for(int i=0;i<=n-l;i++)\n            {\n                int j = i+l-1;\n                diff[i][j] = max(sum[i+1][j]-diff[i+1][j],sum[i][j-1]-diff[i][j-1]);\n            }\n        }\n\n        return diff[0][n-1];\n        \n    }\n};\n```
[]