Data Structures & AlgorithmsVery hardICPC regional · Product Company SDE

Problem: Buses run fixed routes; from a stop, the number of distinct routes is what matters. Given the four routes [1,2,7], [3,6,7], [2,5], [5,8] (each a list of stops), what is the minimum number of routes needed to go from stop 1 to stop 8 by changing buses only at shared stops?

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

Correct answer: D. 3

Treat routes as nodes and connect routes that share a stop; BFS over routes gives the fewest buses. Counting stops along the way instead of buses is a different measure.

More Coding Interview Problems questions

Exams that ask this topic