 All Problems
Balanced Binary Tree
easy
tree
depth-first search
binary tree
amazon
microsoft

Given a binary tree, determine if it is height-balanced.

A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.

Example 1:

Input:  3 9 20 null null 15 7
Output: true

Example 2:

Input:  1 2 2 3 3 null null 4 4
Output: false

Constraints:

  • The number of nodes in the tree is in the range [0, 5000]
  • -10⁴ ≤ Node.val ≤ 10⁴

Input format: BFS level-order, space-separated, null for missing nodes.

Output format: true or false.

Run to check your code against the sample cases, or submit to run every case