Bird
Raised Fist0

Which line contains the subtle bug that can cause incorrect results when seqs is missing some elements from org?

medium🐞 Bug Identification Q14 of Q15
Topological Sort - Sequence Reconstruction (Unique Topo Order)
Examine the following buggy code snippet for sequence reconstruction using DFS postorder topological sort. Which line contains the subtle bug that can cause incorrect results when seqs is missing some elements from org?
ALine 7: Missing check if all nodes in org appear in seqs
BLine 12: Incorrect graph edge insertion logic
CLine 18: Incorrect cycle detection marking
DLine 27: Missing stack reversal before comparison
Step-by-Step Solution
  1. Step 1: Identify missing validation

    The code does not check if all elements in org appear in seqs, which can cause false positives.
  2. Step 2: Confirm other lines are correct

    Graph construction, cycle detection, and stack reversal are implemented correctly.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Missing node presence check leads to incorrect true when seqs incomplete [OK]
Quick Trick: Always verify all org nodes appear in seqs [OK]
Common Mistakes:
MISTAKES
  • Ignoring node presence check
  • Misplacing cycle detection flags
Trap Explanation:
PITFALL
  • Other lines look suspicious but are correct; missing node check is subtle and critical.
Interviewer Note:
CONTEXT
  • Tests candidate's attention to input validation and subtle correctness conditions.
Master "Sequence Reconstruction (Unique Topo Order)" in Topological Sort

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Topological Sort Quizzes