Java solution for the follow up
The idea is simple, keep a count of number of smaller nodes in the current node, and divide and conquer when query.\n```\n    public int kthSmallest(TreeNode ro
The idea is simple, keep a count of number of smaller nodes in the current node, and divide and conquer when query.\n```\n    public int kthSmallest(TreeNode root, int k) {\n        Node node = buildTree(root);\n        return findKth(node, k);\n    }\n    \n    private int findKth(Node node, int k) {\n        if (node == null) {\n            return -1;\n        }\n        if (node.count < k - 1) {\n            return findKth(node.right, k - node.count - 1);\n        } else if (node.count > k - 1) {\n            return findKth(node.left, k);\n        }\n        return node.val;\n    }\n    \n    private Node buildTree(TreeNode root) {\n        if (root == null) {\n            return null;\n        }\n        Node node = new Node(root.val);\n        \n        int count = dfs(root.left);\n        node.count = count;\n        \n        node.left = buildTree(root.left);\n        node.right = buildTree(root.right);\n        return node;\n    }\n    \n    private int dfs(TreeNode root) {\n        if (root == null) {\n            return 0;\n        }\n        return dfs(root.left) + dfs(root.right) + 1;\n    }\n    \n    class Node {\n        Node left;\n        Node right;\n        int val;\n        int count;\n        Node (int val) {\n            this.val = val;\n        }\n    }
[]