Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: In a directed graph on vertices 0–3, the arcs are 0→1, 1→2, 2→0, 2→3. The vertex 3 has no outgoing arcs. How many vertices can reach vertex 3?

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

Correct answer: C. 3

Reverse search from the target: any vertex with an arc into a vertex that can reach 3 can also reach it. Here 2 reaches 3 directly, then 1 and 0 reach 2, so all three other vertices qualify.

More Coding Interview Problems questions

Exams that ask this topic