100% faster || Easy To Understand || C++ Code
**Using DP*\n\n1. Time Complexity : O(N ^ 3)\n2. Space Complexity : O(N ^ 2)***\n\n\nint maxCoins(vector<int>& nums) {\n        \n        int n = nums.size();\n
* ******Using DP******\n\n1. ***Time Complexity : O(N ^ 3)***\n2. ***Space Complexity : O(N ^ 2)***\n\n```\nint maxCoins(vector<int>& nums) {\n        \n        int n = nums.size();\n        \n        int arr[n+2];\n        \n        arr[0] = 1;\n        \n        arr[n+1] = 1;\n        \n        for(int i = 1; i <= n; i++)\n            arr[i] = nums[i-1];\n        \n        int dp[n+2][n+2];\n        memset(dp, 0, sizeof(dp));\n        \n        for(int length = 1; length <= n; length++)\n        {\n            for(int left = 1; left <= (n - length + 1); left++)\n            {\n                int right = left + length - 1;\n                \n                for(int i = left; i <= right; i++)\n                {\n                    dp[left][right] = max(dp[left][right], (arr[left-1] * arr[i] * arr[right+1]) + dp[left][i-1] + dp[i+1][right]);\n                }\n            }\n        }\n        \n        return dp[1][n] ;\n    }\n```
['Dynamic Programming']