Code RoomBalanced BST from sorted array
MediumPrep Room Coding #4521

Balanced BST from sorted array

CodingAlgorithms & data structuresMid–Senior~22 min

Given a sorted array of distinct integers, build a height-balanced binary search tree and return it as a level-order array (null for any missing child), where the chosen root of any subtree is the lower-middle element (for an even-length range, the left of the two middles). Trailing nulls beyond the last real node should be omitted. Return the level-order encoding.

Implement
sorted_array_to_bst(nums: list[int]) → list
Examples
in[[-10,-3,0,5,9]]out[0,-10,5,null,-3,null,9]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 22 min
InputExpectedGot
[[-10,-3,0,5,9]][0,-10,5,null,-3,null,9]not run yetsample