Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: Build a binary search tree by inserting 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 in that order (duplicates are not inserted). Count the nodes at depth exactly 3 (root has depth 0).

  1. A. 3
  2. B. 4
  3. C. 2
  4. D. 5

Correct answer: A. 3

Insertions place 35 and 45 under 40 and 65 under 60, all at depth 3 (root at depth 0). Counting leaves instead would include 20 and 80 and give a different number.

More Coding Interview Problems questions

Exams that ask this topic