Data Structures & AlgorithmsVery hardGoldman Sachs OA · LeetCode medium-hard

How many structurally different binary search trees can be built on the keys 1..7 if the ROOT must be 3?

  1. A. 28
  2. B. 132
  3. C. 42
  4. D. 14

Correct answer: A. 28

With root 3, keys {1,2} form the left subtree in C₂ = 2 ways and keys {4,5,6,7} form the right subtree in C₄ = 14 ways, so 2 × 14 = 28. 132 is C₆ and 429 = C₇ would count all roots; 14 forgets the left side.

More Coding Interview Problems questions

Exams that ask this topic