Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A tree has 7 nodes labelled 1–7 with edges 1-2, 1-3, 3-4, 3-5, 5-6, 5-7. Node 1 is the root. What is the depth of the deepest node (root depth 0)?

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

Correct answer: D. 3

A BFS from the root gives each node's depth, and the maximum is the answer. Counting the number of leaves or the root's degree measures something else.

More Coding Interview Problems questions

Exams that ask this topic