2dbi
Home/AMD/Check if a Binary Tree Is Height-Balanced
AAMD·DSASDE-1Technical Phone Screen

Check if a Binary Tree Is Height-Balanced

Problem

Return true if, for every node, the heights of the two subtrees differ by at most one.

Example

Balanced BST -> true; degenerate list-like tree -> false

Constraints

  • 0 ≤ nodes ≤ 5000

Approach

Bottom-up height returning -1 to short-circuit imbalance. O(n).

added 6 days ago
LeadersAccount