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?
- A. 3
- B. 2
- C. 1
- 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
- Problem: Compute the number of trailing zeros of 25! in base 5 (that is, how many times 5 divides 25!).
- Problem: A stack starts with the characters pushed in the order a, b, c, d. The following pops occur: pop, pop, then push e, pop. Which…
- Problem: The grid 2×3 contains the values [[1,2,3],[4,5,6]]. From the top-left cell you move right or down to the bottom-right, collecting…
- Problem: The sum of the digits of 2^15 is what value?
- Problem: How many subarrays of [2, 4, 1, 3, 6, 5] have an even sum? Run the code. python a = [2, 4, 1, 3, 6, 5] print(sum(1 for i in…
- Problem: How many integers x in [1, 999] satisfy x ≡ 2 (mod 3) and x ≡ 5 (mod 7)? Run the code. python print(sum(1 for x in range(1, 1000)…