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]++
}Discussion 0
Join free to post in the discussion.
Related questions
- What a 504 from Nginx meansBackend Developer
- Python default list surpriseBackend Developer
- Edges in a tree with n nodesBackend Developer
- Most nodes in a binary tree of height 3Backend Developer
- What inorder traversal of a BST givesBackend Developer
- Preorder output of a small treeBackend Developer
- Traversal for freeing a whole treeBackend Developer
- Data structure for level-order traversalBackend Developer