Data Structures & AlgorithmsHardTCS NQT · Product Company SDE

Problem: Dijkstra's shortest distances from source 0 in the directed graph 0→1 (3), 0→2 (1), 2→1 (1), 1→3 (2), 2→3 (6), 3→4 (1), 1→4 (9). How many vertices have an odd shortest distance from 0?

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

Correct answer: B. 2

After computing shortest distances (here by repeated relaxation), count the reachable vertices whose distance is odd. Counting odd-numbered vertices instead is a different quantity.

More Coding Interview Problems questions

Exams that ask this topic