Easy · Trees

Is balanced

Given the root of a binary tree, return true if it is height-balanced (at every node, the heights of the left and right subtrees differ by at most 1) and false otherwise. An empty tree is balanced.

Examples

Example 1

{
  "tree": [3, 9, 20, null, null, 15, 7]
}

Output: balanced

Example 2

{
  "tree": [1, 2, null, 3]
}

Output: not balanced

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems