Binance may represent hierarchical structures such as referral or permission relationships as binary trees. Given a binary tree, determine whether it is height-balanced: at every node, the heights of its left and right subtrees differ by no more than one.
Use a single function that returns True for a balanced tree and False otherwise. The input tree is encoded recursively as [value, left, right], where left and right are either another encoded tree or null. An empty tree is represented by null. The node value can be any integer and does not affect balance.
root, a nested list or null. A non-empty node has the form [value, left, right].Your solution should avoid repeatedly calculating subtree heights, since that can make a skewed tree quadratic. Return as soon as an unbalanced subtree is detected.
def is_balanced(root):