Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: In the directed graph on vertices 1–6 with arcs 1→2, 1→3, 2→4, 3→4, 4→5, 3→6, 6→5, what is the length of the longest directed path (number of arcs)?

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

Correct answer: C. 3

Longest paths in a DAG come from memoised DP over out-neighbours. Using a BFS from the source gives the shortest-path length rather than the longest.

More Coding Interview Problems questions

Exams that ask this topic