Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: A tree on nodes 1–9 has edges 1-2, 2-3, 3-4, 4-5, 5-6, 6-7, 3-8, 8-9. The eccentricity of a node is its largest distance to any other node. How many nodes have the minimum eccentricity (the centre of the tree)?

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

Correct answer: D. 1

Compute each node's eccentricity with BFS and count the minimal values. The centre of a tree can have one or two nodes; reporting the diameter's endpoints is a different set.

More Coding Interview Problems questions

Exams that ask this topic