BUG LAB · Trees
A path away from the root
A tree has a left subtree of height 3 and no right subtree. Inside that left subtree, two height 2 branches meet. What can this code miss?
Java · intentionally broken snippet
int diameter(TreeNode root) {
if (root == null) return 0;
return height(root.left) + height(root.right);
}Assume ordinary supporting code and valid inputs unless the question states otherwise.
Choose an answer before revealing the trace. Keys 1 to 3 work too.