Tree: Depth-First Search - Construct Tree from Inorder and Postorder
In the following recursive function for building a binary tree from inorder and postorder traversals, which line contains a subtle bug that can cause incorrect tree construction or runtime errors?
def build(in_left, in_right, post_left, post_right):
if in_left > in_right:
return None
root_val = postorder[post_right]
root = TreeNode(root_val)
index = inorder_index_map[root_val]
left_tree_size = index - in_left
root.left = build(in_left, index - 1, post_left, post_left + left_tree_size - 1)
root.right = build(index + 1, in_right, post_left + left_tree_size, post_right - 1)
return root
