Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE

Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a shortest distance from vertex 0 strictly greater than 3?

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

Correct answer: D. 2

Run Dijkstra fully, then count distances above 3. Using only direct edges from 0 gives larger distances for some vertices and the wrong count.

More Coding Interview Problems questions

Exams that ask this topic