C# || Solution
\n# Code\n\npublic class Solution\n{\n    private readonly int[] _seen = new int[100001];\n    private int _maxHeight;\n\n    public int[] TreeQueries(TreeNode 
\n# Code\n```\npublic class Solution\n{\n    private readonly int[] _seen = new int[100001];\n    private int _maxHeight;\n\n    public int[] TreeQueries(TreeNode root, int[] queries)\n    {\n        _maxHeight = 0;\n        Dfs(root, 0);\n\n        _maxHeight = 0;\n        Dfs(root, 0);\n\n        return queries.Select(q => _seen[q]).ToArray();\n    }\n\n    private void Dfs(TreeNode root, int h)\n    {\n        if (root == null)\n            return;\n        \n        _seen[root.val] = Math.Max(_seen[root.val], _maxHeight);\n        _maxHeight = Math.Max(_maxHeight, h);\n        \n        Dfs(root.left, h + 1);\n        Dfs(root.right, h + 1);\n        \n        (root.right, root.left) = (root.left, root.right);\n    }\n}\n```
['C#']