Is the tree balanced?
A binary tree is height-balanced if, at every node, the heights of the left and right
subtrees differ by at most one. Write is_balanced(root).
is_balanced([3, 9, 20, None, None, 15, 7]) -> True
is_balanced([1, 2, 2, 3, 3, None, None, 4, 4]) -> False
is_balanced(None) -> True
The point is to practise a recursion that returns extra information upward so each node is visited once: return the height, or a sentinel meaning "unbalanced below".
def is_balanced(root):
...