Compute heights bottom-up and stop early if any subtree is unbalanced.
DFS returns subtree height, or -1 to signal imbalance. A node is unbalanced if child heights differ by more than 1.
Every subtree’s balance depends only on its children’s heights and balance status.
Compute heights bottom-up and stop early if any subtree is unbalanced.
DFS returns subtree height, or -1 to signal imbalance. A node is unbalanced if child heights differ by more than 1.
Every subtree’s balance depends only on its children’s heights and balance status.