Data Structures & AlgorithmsVery hardCodeforces Div2 B · TCS CodeVita

A rooted tree has these parent→child edges: 7→80, 70→81, 53→7, 93→59, 93→53, 80→21, 15→17, 17→96, 15→70, 96→93, 70→5, 59→18. The root is at depth 0. How many nodes lie at depth exactly 3?

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

Correct answer: D. 1

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