Code Room
CodingMediumcod-g771
Subject Balanced treesLevel Mid–Senior~22 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.