Easy To Understand Solution TC: O(N).
Intuition\n Describe your first thoughts on how to solve this problem. \n\nTO Solve this Question ASK YOUR SELF:\n\nQ1: How can i find the level of any node in 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nTO Solve this Question ASK YOUR SELF:\n\nQ1: How can i find the level of any node in O(1) by using extra space.\n\nQ2:How can i find all the nodes at a particular level and their depths in O(1) by precomputation.\n\nQ3: If I am deleting a node at particular level and that node has the highest / largest depth in that level then what will be the new height of tree.\n\n{RE THINK} Q2: In a particular node Do i need to find (all the nodes and their depths) or (only the node with highest and second Highest depths)\n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(N)+O(2N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\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   \n    int mp[100001]={0};\n\n    int dfs(TreeNode* curr,int level,vector<vector<pair<int,int>>>&vec)\n    {\n        if(!curr)\n            return -1;\n\n        //later using this mp you can find the level of any node in O(1)\n        mp[curr->val]=level;\n\n        int l=1+dfs(curr->left,level+1,vec);\n        int r=1+dfs(curr->right,level+1,vec);\n        int h=max(l,r);\n\n        //store  the highest and second highest depth of each level in vec\n        if(vec[level][0].second<=h)\n        {\n            auto pr=vec[level][0];\n            vec[level][0]={curr->val,h};\n            vec[level][1]=pr;\n        }\n        else if(vec[level][1].second<=h)\n        {\n            vec[level][1]={curr->val,h};\n        }\n        \n        //maximum depth of a node is maximum of its left and right child\n        return max(l,r);\n    }\n\n    vector<int> treeQueries(TreeNode* root, vector<int>& queries) {\n        int n=100001;\n        \n        memset(mp,-1,sizeof(mp));\n\n        vector<vector<pair<int,int>>>vec(n,vector<pair<int,int>>(2,{0,0}));\n\n        //mxht means Maximum height\n        int mxht=dfs(root,0,vec);\n\n        vector<int>ans;\n\n        for(auto nd:queries)\n        {\n            auto &v=vec[mp[nd]];\n\n            int x=mxht;\n            \n            //(v[0].first==nd) means => If the node i am deleting has the highest depth in this level. \n            //Then the new max height of the tree will be the  level i am standing at (mp[v[1].first]) + second highest depth in that level (v[1].second)\n\n\n            // if(v[0].first != nd) means => If the node i am deleting is not the node with highest depth in the level then the height will not change at all.\n\n\n            // (v[1].first==0) means=> If the level has only one node then the new height will be maximum height - the level of the node where i am standing now\n\n            if(v[0].first==nd)\n            {\n                x=(v[1].first==0)?(mp[v[0].first]-1):mp[v[1].first]+v[1].second;\n            }\n            ans.push_back(x);    \n        }\n\n        return ans;\n    }\n};\n```
['C++']