Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: Consider the directed graph with arcs 1→2, 2→3, 3→4, 4→2, 1→5. Starting from 1, how many distinct vertices are reachable (including 1)?

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

Correct answer: C. 5

The reachable set from 1 is {1, 2, 3, 4, 5}, and the cycle 2→3→4→2 does not add any new vertices beyond these.

More Coding Interview Problems questions

Exams that ask this topic