Given a binary tree, determine if it is height-balanced. A binary tree in which the left and right subtrees of every node differ in height by no more than 1.
root = [3,9,20,null,null,15,7]trueroot = [1,2,2,3,3,null,null,4,4]falseroot = [1,2,3,4,5]truenode == null → return 0 (null height is 0)L = height(node.left) — if L == −1, propagate −1 immediatelyR = height(node.right) — if R == −1, propagate −1 immediately|L − R| > 1 → this node is unbalanced, return −11 + max(L, R) — the actual height of this balanced subtreeUsing −1 as sentinel avoids a second pass. As soon as any subtree is unbalanced, all ancestor calls propagate −1 upward instantly — O(n) single-pass check. The recursion visits every node exactly once in post-order (children before parent), so when we check |L−R|, both subtree heights are already available. If the root receives a real height (≥ 0), the tree is balanced.