Convert a Sorted Array to a Balanced BST

Easy · Binary Search Trees · about 15 minutes

Asked at Amazon, Microsoft, Airbnb.

nums lists distinct values in ascending order. Build a binary search tree holding exactly these values in which, at every node, the two subtrees' heights differ by at most one (a height-balanced tree). Return its root.

Related guides