153. Convert Sorted Array to BST

Easy · Binary Tree

Given a sorted array of integers in ascending order, build a height-balanced binary search tree (BST) and return it as a level-order array.

A height-balanced BST is one where the left and right subtrees of every node differ in height by at most 1.

**Input format:** A sorted array of integers (ascending order).

**Output format:** Return the tree as a level-order (breadth-first) array representation. Use `null` for missing nodes, and trim any trailing `null` values. When recursively building the tree, always pick the midpoint using `mid = (l + r) >> 1` (left-biased) to ensure the canonical shape.

Examples

Example 1
Input: [-10,-3,0,5,9]
Output: [0,-10,5,null,-3,null,9]
Explanation: Left-biased mid gives 0 at the root with -10 left and 5 right
Example 2
Input: [1,3]
Output: [1,null,3]
Explanation: (l+r)>>1 = 0 → root 1, right 3

Constraints