35 / 75
E

Balanced Binary Tree

#35
treedfsrecursion

Check if tree is height-balanced: at every node, left and right heights differ by at most 1.

Example:

Input:root=[3,9,20,null,null,15,7]
Output:true

Common Mistakes:

  • Only checking balance at root (must check at every node)
  • Recalculating heights multiple times (inefficient O(n²))
  • Not propagating unbalanced state up the recursion
  • Confusing with complete/perfect binary tree definitions

Notes:

Use -1 as sentinel for unbalanced state. Time O(n), Space O(h). Efficient single-pass solution.

35/75
Balanced Binary Tree