Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: An undirected graph on 6 vertices has edges 0-1, 1-2, 2-3, 3-0, 3-4, 4-5. Find the number of vertices whose removal leaves a graph that still has exactly one connected component (the removed vertex is not counted in the components). Count such vertices.

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

Correct answer: C. 4

For each vertex, delete it and count the remaining components with union-find. Deleting a cut vertex splits the graph, so only the non-cut vertices keep one component.

More Coding Interview Problems questions

Exams that ask this topic