Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A rooted tree (root 1) has children lists: 1: [2, 3], 2: [4, 5, 6], 3: [7], 4: [], 5: [8], 6: [], 7: [9], 8: [], 9: []. How many leaves lie at an even depth (the root has depth 0)?

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

Correct answer: A. 2

Walk the tree tracking depth and count leaves whose depth is even. Counting internal nodes at even depth is a different quantity.

More Coding Interview Problems questions

Exams that ask this topic