Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: A directed graph on vertices 0–5 has arcs 0→1, 1→2, 2→0, 2→3, 3→4, 4→3, 4→5, 5→1. How many vertices have in-degree equal to out-degree?

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

Correct answer: C. 2

Tally in-degrees and out-degrees separately from the arc list, then compare per vertex. Comparing total degree (sum of both) with the counts gives a different test.

More Coding Interview Problems questions

Exams that ask this topic