Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 92→67, 4→89, 92→4, 78→54, 71→70, 54→57, 71→96, 70→10, 93→92, 22→78, 93→71, 70→22. The root is at depth 0. How many nodes lie at depth exactly 3?

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

Correct answer: B. 3

Count the nodes whose depth is exactly 3, by computing each node's depth from the root. Off-by-one on the depth, or counting cumulatively, gives the trap values.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic