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?

  1. A. 3
  2. B. 1
  3. C. 2
  4. 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

Exams that ask this topic