Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional
Problem: A DAG with vertices 0–5 has weighted edges 0→1 (2), 0→2 (1), 1→3 (2), 2→3 (3), 2→4 (1), 3→5 (1), 4→5 (5). How many distinct shortest paths (by total weight) go from vertex 0 to vertex 5?
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Counting shortest paths in a DAG needs shortest distances first, then a count over tight edges only (d[u]+w = d[v]). Counting every path ignores the weight condition.
More Coding Interview Problems questions
- Problem: An undirected connected graph has 9 vertices and 13 edges. What is the cyclomatic number (the number of independent cycles…
- Problem: An undirected graph on 7 vertices (0–6) has degrees 0:3, 1:2, 2:4, 3:1, 4:2, 5:3, 6:1. How many vertices have odd degree? (Such a…
- Problem: Vertices 0–5 with undirected edges 0-1, 1-2, 2-0, 2-3, 3-4, 4-5, 5-3. How many articulation points (cut vertices, whose removal…
- Problem: Using a min-heap, the stream 9, 4, 7, 1, 8, 2, 6, 3, 5 is processed as follows: after each insertion, pop the minimum if the heap…
- Problem: For the array [4, 1, 5, 2, 6, 3, 7], compute, for each index i, the distance to the next strictly greater element to its right (0…
- Problem: The maximum of each window of length 3 in [1, 3, −1, −3, 5, 3, 6, 7] is recorded for all windows. What is the sum of these window…