Java Clean Solution
Code\njava []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * 
# Code\n```java []\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = left;\n * this.right = right;\n * }\n * }\n */\nclass Solution {\n    int[] po = new int[100001];\n    int[] po_ = new int[100001];\n    int maxH = 0;\n\n    private void preOrder(TreeNode root, int height) {\n        // edge\n        if (root == null) {\n            return;\n        }\n\n        po[root.val] = maxH;\n        maxH = Math.max(maxH, height);\n        preOrder(root.left, height + 1);\n        preOrder(root.right, height + 1);\n    }\n\n    private void postOrder(TreeNode root, int height) {\n        // edge\n        if (root == null) {\n            return;\n        }\n\n        po_[root.val] = maxH;\n        maxH = Math.max(maxH, height);\n        postOrder(root.right, height + 1);\n        postOrder(root.left, height + 1);\n    }\n\n    public int[] treeQueries(TreeNode root, int[] queries) {\n        preOrder(root, 0);\n        maxH = 0;\n        postOrder(root, 0);\n\n        int[] res = new int[queries.length];\n        for (int i = 0; i < res.length; i++) {\n            res[i] = Math.max(po[queries[i]], po_[queries[i]]);\n        }\n        return res;\n    }\n}\n```
['Array', 'Tree', 'Depth-First Search', 'Breadth-First Search', 'Binary Indexed Tree', 'Binary Search Tree', 'Binary Tree', 'Java']