Appraoch:Usingdfs
Intuition\nHere we can get the max height after remobing a node by storing the height and depth od each node in the tree and then using this info to \ncreate a 
# Intuition\nHere we can get the max height after remobing a node by storing the height and depth od each node in the tree and then using this info to \ncreate a cousins map which basically takes current depth(level) as the key and the top 2 nodes with the maximum height in that level. The ideology ios that if we delete a node in a level, \n- The max path can be = height of Tree if the node deleted is not the node with maxHeight in that level\n- The max path can be = depth of current Level+ height of second best node\n- The max Path can be= depth of current level-1 if only one node in that level\nSo by this way we can get maxPath for each queries\n# Approach\n- in ```height_depthDFS``` we store the hight and depth of each node\n- first we calculate height of Tree ```height_depthDFS(root,0)```\n- Now we create and store the top2 nodes with maxHeight in each level\n    - ```cousins[depth].push_back({heightNodes[node],node});```\n    - We sort these in descending order\n    - then remove nodes outside top3 in each iteration as they are not needed\n- Finally we consder 3 cases which i discussed above\n    -   ```if(cousins[depthQ].size()==1)```\n    - ```else if(cousins[depthQ][0].second==q)```\n    - ```else result.push_back(heightTree);```\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# 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>depthNodes;\n    unordered_map<int,int>heightNodes;\n    int height_depthDFS(TreeNode*root,int level){\n        if(!root) return-1;\n        depthNodes[root->val]=level;\n        heightNodes[root->val]=1+max(height_depthDFS(root->left,level+1),height_depthDFS(root->right,level+1));\n        return heightNodes[root->val];\n    }\n    vector<int> treeQueries(TreeNode* root, vector<int>& queries) {\n        int heightTree=height_depthDFS(root,0);\n        vector<int>result;\n        unordered_map<int,vector<pair<int,int>>>cousins;\n        for(auto&[node,depth]:depthNodes){\n            cousins[depth].push_back({heightNodes[node],node});\n            sort(cousins[depth].begin(),cousins[depth].end(),greater<pair<int,int>>());\n            if(cousins[depth].size()>2) cousins[depth].pop_back();\n        }\n        for(auto&q:queries){\n            int depthQ=depthNodes[q];\n            if(cousins[depthQ].size()==1) result.push_back(depthQ-1);\n            else if(cousins[depthQ][0].second==q) result.push_back(cousins[depthQ][1].first+depthQ);\n            else result.push_back(heightTree);\n        }\n        return result;\n\n    }\n};\n```
['C++']