Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: A graph's adjacency list is 0: [1, 2], 1: [3], 2: [3, 4], 3: [5], 4: [5], 5: []. What is the number of distinct topological orders of this DAG?

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

Correct answer: D. 5

A topological order is a permutation that places every arc's tail before its head. Here 0 must come first and 5 last, and the middle vertices admit a few interleavings.

More Coding Interview Problems questions

Exams that ask this topic