Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Vertices 0–4 have undirected edges 0-1 (3), 1-2 (1), 2-3 (4), 3-4 (2), 0-4 (6), 1-4 (5). A path's cost is the sum of its edge weights. Among all simple paths from 0 to 3, what is the minimum cost?

  1. A. 8
  2. B. 10
  3. C. 16
  4. D. 21

Correct answer: A. 8

Both 0→1→2→3 (3 + 1 + 4) and 0→4→3 (6 + 2) cost 8, and no simple path is cheaper. 0→1→4→3 costs 10, the longest route 0→4→1→2→3 costs 16, and 21 sums every edge.

More Coding Interview Problems questions

Exams that ask this topic