Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: In a directed acyclic graph with arcs 0→1, 0→2, 1→3, 2→3, 3→4, 2→4, how many distinct topological orders exist?

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

Correct answer: B. 2

A topological order respects every arc. Vertex 0 must come first and vertex 4 last, while 1 and 2 may appear in either order before vertex 3, which gives two orders.

More Coding Interview Problems questions

Exams that ask this topic