C++ | DFS
```\nclass Solution {\npublic:\n    unordered_map l,r,ans;\n    int height(TreeNode root){\n        if(root==NULL) return 0;\n        int le = height(root->left
```\nclass Solution {\npublic:\n    unordered_map<int,int> l,r,ans;\n    int height(TreeNode* root){\n        if(root==NULL) return 0;\n        int le = height(root->left);\n        int re = height(root->right);\n        l[root->val] = le;                 // Storing maximum height in the left side of current node\n        r[root->val] = re;                 // Storing maximum height in the right side of current node\n        return max(le,re)+1;      \n    }\n    void fun(TreeNode* root,int MaxSoFar,int depth){\n        if(root==NULL) return;\n\n        ans[root->val] = MaxSoFar;\n        fun(root->left,max(MaxSoFar,depth+r[root->val]),depth+1);\n        fun(root->right,max(MaxSoFar,depth+l[root->val]),depth+1);\n    }\n    vector<int> treeQueries(TreeNode* root, vector<int>& q) {\n        height(root);\n        \n        fun(root->left,r[root->val],1);               // Calling on left side and passing the maximum height of right side of root\n        fun(root->right,l[root->val],1);              // Calling on right side and passing the maximum height of left side of root\n        \n        vector<int> res(q.size());\n        for(int i = 0;i<q.size();i++){\n            res[i] = ans[q[i]];\n        }\n        return res;\n    }\n};
['Depth-First Search', 'Recursion', 'C']