Height balanced binary tree

Write codeMedium20 min

Your task

Given a binary tree as a level-order array arr (null for missing), return True if it is height-balanced, for every node, the heights of its two subtrees differ by at most 1, and False otherwise. An empty tree is balanced. 0 <= node count <= 50000.

Examples

is_balanced(arr: list[int]) -> bool
Example 1
Inputis_balanced([3, 9, 20, None, None, 15, 7])
OutputTrue