✅Easy C++|| Height and Depth || Preorder Traversal
Code\n\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : 
# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    unordered_map<int,int> lheight;\n    unordered_map<int,int> rheight;\n    unordered_map<int,int> res;\n    int findHeight(TreeNode* root)\n    {\n        if(root==NULL)\n        return 0;\n\n        int left= findHeight(root->left);\n        int right= findHeight(root->right);\n\n        lheight[root->val]= left;\n        rheight[root->val]= right;\n\n        return 1+ max(left, right);\n\n    }\n    void newHeight(TreeNode* root, int maxi, int level)\n    {\n        if(root==NULL)\n        return;\n        res[root->val]= maxi;\n        newHeight(root->left, max(maxi, level + rheight[root->val]), level+1);\n        newHeight(root->right, max(maxi, level + lheight[root->val]), level+1);\n    }\n    vector<int> treeQueries(TreeNode* root, vector<int>& queries) {\n        int m= queries.size();\n        lheight.clear();\n        rheight.clear();\n        res.clear();\n        vector<int> answer(m, 0);\n        if(root==NULL) return answer;\n        findHeight(root);\n        newHeight(root, 0, 0);\n\n        for(int i=0; i<m; i++)\n        {\n            answer[i]=res[queries[i]];\n        }\n        return answer;\n    }\n};\n```
['C++']