Javascript | DP | DFS | Recursive | Memoization | Easy and Fast
\n// Recursive Approach: TLE\nvar integerBreak = function (n) {\n    let res = 1;\n\n    function dfs(num) {\n        if (num === 1) return 1;\n\n        let re
```\n// Recursive Approach: TLE\nvar integerBreak = function (n) {\n    let res = 1;\n\n    function dfs(num) {\n        if (num === 1) return 1;\n\n        let res = num;\n        for (let i = 1; i <= num; i++) {\n            const tmpRes = i * dfs(num - i);\n            res = Math.max(tmpRes, res);\n        }\n\n        return res;\n    }\n    for (let i = 1; i < n; i++) {\n        const tmpRes = i * dfs(n - i);\n        res = Math.max(tmpRes, res);\n    }\n    return res;\n};\n\n// console.log(integerBreak(10));\n// console.log(integerBreak(2));\n\n\n// Memoized recursion\nvar integerBreak = function (n) {\n    let res = 1;\n    let dp = new Array(n + 1).fill(-1);\n    function dfs(num) {\n        if (num === 1) return 1;\n\n        if (dp[num] !== -1) return dp[num];\n        let res = num;\n        for (let i = 1; i <= num; i++) {\n            const tmpRes = i * dfs(num - i);\n            res = Math.max(tmpRes, res);\n        }\n\n        return dp[num] = res;\n    }\n    for (let i = 1; i < n; i++) {\n        const tmpRes = i * dfs(n - i);\n        res = Math.max(tmpRes, res);\n    }\n    return res;\n};\n\nconsole.log(integerBreak(10));\n```
['Dynamic Programming', 'Depth-First Search', 'Recursion', 'JavaScript']