Simple || C++ || Using Map
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    map<int, int> l, r, h;\n    int height (TreeNode *root)\n    {\n        if(!root) return 0;\n        int lh = height (root->left);\n        int rh = height (root->right);\n        l[root->val] = lh;\n        r[root->val] = rh;\n        return max(lh, rh)+1;\n    }\n    void solve(TreeNode *root, int maxa, int depth)\n    {\n        if(!root) return;\n        h[root->val] = maxa;\n        solve(root->left, max(maxa, depth+r[root->val]), depth+1);\n        solve(root->right, max(maxa, depth+l[root->val]), depth+1);\n    }\n    vector<int> treeQueries (TreeNode* root, vector<int>& q)\n    {\n        height (root);\n        solve(root->left, r[root->val], 1);\n        solve(root->right, l[root->val], 1);\n        vector<int> ans;\n        for (int i=0; i<q.size(); i++) ans.push_back(h[q[i]]);\n        return ans;\n    }\n};\n```
['C++']