Data Structures & AlgorithmsVery hardProduct company OA

Flights (directed, cost): 0→1 100, 1→2 100, 2→3 100, 0→2 500, 1→3 600, 0→3 900. What is the cheapest cost from 0 to 3 using AT MOST 1 stopover (at most 2 flights)? (Run Bellman–Ford for exactly k + 1 = 2 rounds, relaxing from a copy of the previous round.)

  1. A. 600
  2. B. 300
  3. C. 700
  4. D. 900

Correct answer: A. 600

Two-flight routes to 3: 0→1→3 = 700, 0→2→3 = 600; direct 0→3 = 900. Best within the limit: 600. The overall cheapest 0→1→2→3 = 300 needs 2 stopovers. Relaxing in place (without the copy) can chain several edges in one round and wrongly report 300.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic