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?
- A. 6
- B. 4
- C. 7
- 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
- Problem: The number of integers from 1 to 100 that have exactly three divisors is what value? (Numbers with exactly three divisors are…
- Problem: What is the number of inversions in the array [4, 3, 2, 1, 0]?
- Problem: The string "cabbage" is sorted by letter using a stable sort on the letters only. What is the 4th character of the sorted string?
- Problem: Starting with 1, the operations are: multiply by 2, then add 3, applied three times in a row (x → 2x + 3). What is the result…
- Problem: Find the number of integers n in the range 2 to 100 for which n and n + 2 are both prime (twin primes, counted by the smaller…
- Problem: The string "abcabcabcabc" is split into consecutive chunks of length 5 from the left (the last chunk may be shorter). How many…