Data Structures19 sections · 729 units
Open in Course

Problem - Sorted Array to BST

Build a balanced BST

Given an integer array where elements are sorted in ascending order, convert it to a height-balanced BST.

A height-balanced BST is one where the depth of the two subtrees of every node never differs by more than one.

Example: [10,3,0,5,9][-10,-3,0,5,9] could become [0,3,9,10,null,5][0,-3,9,-10,null,5] or [0,10,5,null,3,null,9][0,-10,5,null,-3,null,9]. This problem teaches you how to construct balanced trees from sorted data. Constraints: array length from 11 to 10410^4, values from 104-10^4 to 10410^4.