#108

Convert Sorted Array to Binary Search Tree

Easy Middle as root

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Turn a sorted array into a height-balanced BST.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: build a height-balanced BST from a sorted array.

Why this works: the middle value as root splits the rest evenly; repeat on both halves.

Example: [-10, -3, 0, 5, 9]

root 0, left from [-10, -3] → -3 (-10), right from [5, 9] → 9 (5)

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Inserting elements one by one in order — that builds a linked-list-shaped tree.

Solve on LeetCode ↗
Complexity
  • Time: O(n).
  • Space: O(log n) recursion.
Topic: Binary Search Trees
🎬 Episodes 61–63: video coming soon