Build a Height-Balanced BST From a Sorted Singly Linked List
Company: Meta
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Technical Screen
Overview: A coding problem that asks you to turn a sorted singly linked list into a height-balanced binary search tree and return it in level order, with a subtree size rule that makes the answer unique. It tests recursive construction over list ranges and careful tree serialization.
Read the full Meta Software Engineer interview experience this question came from
Constraints
- 0 <= len(values) <= 2 * 10^4
- -10^5 <= values[i] <= 10^5
- values is strictly increasing.
Examples
Input: ([],)
Expected Output: []
Explanation: An empty list gives an empty tree.
Input: ([7],)
Expected Output: [7]
Explanation: A single value is the root; its two missing children are trailing None entries and are removed.
Hints
- For a list of length n, work out how many values the size rule places in the left subtree and how many in the right; that count tells you which value sits at the root.
- Every subtree is built from a contiguous slice of the list, and the same rule applies inside it.
- In the output, only nodes that exist contribute child entries, and trailing None entries are dropped at the end.