Build a BST from a list

Problem Deliberately open-ended: given "any list", construct a binary search tree from it. The interviewer expects clarifying questions before code — element type/comparability, duplicates, sortedness, and what "good" means (any BST vs balanced).

Input / Output

  • Input: a list of comparable values (assume ints after clarification).
  • Output: the root of a BST containing all values.

Constraints

  • Unsorted input, n up to 10^5.
  • Duplicate policy must be asked (reject, count, or a consistent side).

Example

  • [7,2,9,1,5] inserted sequentially -> BST rooted at 7 with 2(1,5) and 9.
asked …
LeaderboardSalaryAccount