Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Consider the directed graph with arcs 1→2, 2→3, 3→1, 3→4, 4→2, 4→5. How many vertices can reach vertex 5?

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

Correct answer: A. 4

Reverse reachability: start from vertex 5 and repeatedly add any vertex with an arc into the set. Counting only direct predecessors of 5 would miss vertices that reach it through a chain.

More Coding Interview Problems questions

Exams that ask this topic