Clean JavaScript solution
Idea\n\ndp[i][j] = maxCoins(nums[i:j])\ndp[i][j] = max { dp[i][k - 1] + vals[i - 1] * vals[k] * vals[j + 1] + dp[k + 1][j], i <= k <= j }\n\nres = dp[1][n]\n\n\
**Idea**\n\ndp[i][j] = maxCoins(nums[i:j])\ndp[i][j] = max { dp[i][k - 1] + vals[i - 1] * vals[k] * vals[j + 1] + dp[k + 1][j], i <= k <= j }\n\nres = dp[1][n]\n\n```\nconst maxCoins = (nums) => {\n  const vals = [1, ...nums, 1];\n  const n = nums.length;\n  const dp = [...Array(n + 2)].map(() => Array(n + 2).fill(0));\n  for (let len = 1; len <= n; len++) {\n    for (let i = 1; i + len <= n + 1; i++) {\n      const j = i + len - 1;\n      for (let k = i; k <= j; k++) {\n        dp[i][j] = Math.max(\n          dp[i][j],\n          dp[i][k - 1] + vals[i - 1] * vals[k] * vals[j + 1] + dp[k + 1][j],\n        );\n      }\n    }\n  }\n  return dp[1][n];\n};\n```\n
['Dynamic Programming', 'JavaScript']