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

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Trees problems