Javascript Easy to Understand DFS
Inspired by this solution and re-written in JS: https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/discuss/2758375/Python3-C%2B%2
Inspired by this solution and re-written in JS: https://leetcode.com/problems/height-of-binary-tree-after-subtree-removal-queries/discuss/2758375/Python3-C%2B%2B-Clean-9-lines-Dfs\n\n```\nvar treeQueries = function(root, queries) {\n    if (!root) return [];\n    \n    let ans = {};\n    let heights = {}\n    \n    function maxHeight(node) {\n        if (!node) return 0;\n        \n        if (heights[node.val]) return heights[node.val];\n        \n        heights[node.val] = 1 + Math.max(maxHeight(node.left), maxHeight(node.right));\n        \n        return heights[node.val];\n    }\n    \n    function dfs(node, depth, maxDepthWithoutCurrentNode) {\n        if (!node) return 0;\n        \n        ans[node.val] = maxDepthWithoutCurrentNode;\n        \n        // depth + height(node.right)\n        // Add current depth + depth of opposite child (since we act as if we remove one of the children)\n        dfs(node.left, depth + 1, Math.max(maxDepthWithoutCurrentNode, depth + maxHeight(node.right)));\n        dfs(node.right, depth + 1, Math.max(maxDepthWithoutCurrentNode, depth + maxHeight(node.left)));\n    }\n    \n    dfs(root, 0, 0);\n    \n    return queries.map(q => ans[q]);\n};\n```
['Depth-First Search', 'JavaScript']