JavaScript Clean DFS
Solution - 1\njavascript\nvar buildTree = function(inorder, postorder) {\n    \n    function callDFS(arr) {\n        if(!arr.length) return null;\n        const
## Solution - 1\n```javascript\nvar buildTree = function(inorder, postorder) {\n    \n    function callDFS(arr) {\n        if(!arr.length) return null;\n        const val = postorder.pop();\n        const idx = arr.indexOf(val);\n        const node = new TreeNode(val);\n        node.right = callDFS(arr.slice(idx+1));\n        node.left = callDFS(arr.slice(0, idx));\n        return node;\n    }\n    \n    return callDFS(inorder);\n};\n```\n\n## Solution - 2: Optimized Using Hash Map\n```javascript\nvar buildTree = function(inorder, postorder) {\n    const map = new Map();\n    \n    for(let i = 0; i < inorder.length; i++) {\n        map.set(inorder[i], i);\n    }\n    \n    function callDFS(start, end) {\n        if(start > end) return null;\n        const val = postorder.pop();\n        const idx = map.get(val);\n        const node = new TreeNode(val);\n        node.right = callDFS(idx+1, end);\n        node.left = callDFS(start, idx-1);\n        return node;\n    }\n    \n    return callDFS(0, inorder.length-1);\n};\n```
['JavaScript']