Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: On the undirected graph with edges 0-1 (4), 0-2 (1), 2-1 (2), 1-3 (5), 2-3 (9), 3-4 (3), find the minimum number of edges used by any path of minimum total weight from vertex 0 to vertex 4.

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

Correct answer: D. 4

Lexicographic Dijkstra on (weight, edges) pairs picks the fewest edges among minimum-weight paths. Ignoring the tie-break can return a longer path with the same weight.

More Coding Interview Problems questions

Exams that ask this topic