Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A rooted tree (root 1) has children 1: [2, 3], 2: [4], 3: [5, 6], 5: [7]. What is the number of nodes at depth 2 (root at depth 0)?

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

Correct answer: C. 3

Depth-2 nodes are the grandchildren of the root: 4, 5 and 6. Counting leaves instead gives a different number.

More Coding Interview Problems questions

Exams that ask this topic