DP Solution in Javascript (Recursion + Dp Memo + Dp tabulation)
1. Recursion\n\n\nfunction solveRec(value, i, j) {\n  // base case\n  if (i + 1 === j) return 0;\n  let ans = Number.MAX_VALUE;\n  for (let k = i + 1; k < j; k+
**1. Recursion**\n\n````\nfunction solveRec(value, i, j) {\n  // base case\n  if (i + 1 === j) return 0;\n  let ans = Number.MAX_VALUE;\n  for (let k = i + 1; k < j; k++) {\n    ans = Math.min(\n      ans,\n      value[i] * value[j] * value[k] +\n        solveRec(value, i, k) +\n        solveRec(value, k, j)\n    );\n  }\n  return ans;\n}\nvar minScoreTriangulation = function (values) {\n  let n = values.length;\n  return solveRec(values, 0, n - 1);\n};\n````\n\n**2. Recursion + memoization (Top down approach)**\n\n````\nfunction solveMem(value, i, j, dp) {\n  // base case\n  if (i + 1 === j) return 0;\n  if (dp[i][j] !== -1) return dp[i][j];\n  let ans = Number.MAX_VALUE;\n  for (let k = i + 1; k < j; k++) {\n    ans = Math.min(\n      ans,\n      value[i] * value[j] * value[k] +\n        solveMem(value, i, k, dp) +\n        solveMem(value, k, j, dp)\n    );\n  }\n  dp[i][j] = ans;\n  return dp[i][j];\n}\nvar minScoreTriangulation = function (values) {\n  let n = values.length;\n  let dp = new Array(n).fill(-1).map(() => Array(n).fill(-1));\n  return solveMem(values, 0, n - 1, dp);\n};\n````\n\n**3. Bottom up approach (Tabulation)**\n\n```\nfunction solveTab(value) {\n  // base case\n  let n = value.length;\n  let dp = new Array(n).fill(0).map(() => Array(n).fill(0));\n  for (let i = n - 1; i >= 0; i--) {\n    for (let j = i + 2; j < n; j++) {\n      let ans = Number.MAX_VALUE;\n      for (let k = i + 1; k < j; k++) {\n        ans = Math.min(\n          ans,\n          value[i] * value[j] * value[k] + dp[i][k] + dp[k][j]\n        );\n      }\n      dp[i][j] = ans;\n    }\n  }\n\n  return dp[0][n - 1];\n}\nvar minScoreTriangulation = function (values) {\n  let n = values.length;\n  return solveTab(values);\n};\n\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'JavaScript']