Check if a Binary Tree Is Height-Balanced

Problem Given a binary tree, determine whether it is height-balanced: for every node, the heights of its left and right subtrees differ by at most one.

Input / Output

  • Input: the tree root.
  • Output: true if balanced at every node, false otherwise.

Constraints

  • 0 <= nodes <= 5000. The empty tree is balanced.
  • Aim for O(n) — recomputing height per node is O(n^2).

Example

  • A complete / AVL-shaped tree -> true.
  • A degenerate list-like tree (each node has a single child) -> false once a depth difference exceeds 1.
added …
LeaderboardSalaryAccount