Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: Count the vertices of the tree with edges 0–1, 0–2, 1–3, 1–4, 2–5, 5–6, 5–7 whose removal leaves every remaining connected component with at most 3 vertices. (A vertex is removable only as an ordinary node; the count asks how many such vertices exist.)

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

Correct answer: C. 2

Removing each vertex in turn and measuring every remaining component with DFS is the direct test. Degree alone does not decide the condition.

More Coding Interview Problems questions

Exams that ask this topic