Skip to content
RED SAGSkills
hard20 pts · first answer countsgraphstopological-sortdebugging

Kahn’s algorithm hangs on duplicate edges

This code reports a false cycle when the input lists the same dependency twice, such as ["b", "a"] two times. Why?

for (const [a, b] of deps) {
  if (!adj[b].includes(a)) adj[b].push(a)
  indeg[a]++
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions