Stone Game VII || C++ || Bottom Up Approach || DP
CODE :\n\nclass Solution {\npublic:\n    int stoneGameVII(vector<int>& stones) {\n        int n = stones.size();\n        \n        //precomputation \n        i
**CODE :**\n```\nclass Solution {\npublic:\n    int stoneGameVII(vector<int>& stones) {\n        int n = stones.size();\n        \n        //precomputation \n        int prefixSum[n];\n        prefixSum[0] = stones[0];\n        \n        for(int i=1;i<n;i++)\n            prefixSum[i] = stones[i] + prefixSum[i-1];\n        \n        // code\n        int dp[n][n];\n        for(int i=0;i<n-1;i++){\n            dp[i][i+1] = max(stones[i], stones[i+1]);\n        }\n        for(int gap=2;gap<n;gap++)\n        {\n            for(int i=0;i+gap<n;i++){\n                int j = i+gap;\n                \n                int sum = prefixSum[j];\n                \n                if(i>0)\n                    sum -= prefixSum[i-1];\n                \n                dp[i][j] = max(sum-stones[i]-dp[i+1][j], sum-stones[j]-dp[i][j-1]);\n            }\n        }\n        return dp[0][n-1];\n    }\n};\n```\nDO **UPVOTE** IF YOU LIKED IT !!
[]