Bird
Raised Fist0

What is the output of findOrder(1, []) using Kahn's Algorithm implementation?

medium🧾 Code Trace Q4 of Q15
Topological Sort - Course Schedule II (Topological Order)
What is the output of findOrder(1, []) using Kahn's Algorithm implementation?
A[0]
B[]
C[1]
DError due to empty prerequisites
Step-by-Step Solution
Solution:
  1. Step 1: Initialize in-degree and queue

    With one course (index 0), no prerequisites, in-degree[0] = 0, queue = [0].
  2. Step 2: Process queue

    Pop 0, append to order -> [0]. No neighbors to process.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Single course with no prereqs -> order [0] [OK]
Quick Trick: Single node with zero in-degree -> output that node [OK]
Common Mistakes:
MISTAKES
  • Confusing course numbering starting at 0
  • Assuming empty prerequisites means no courses
Trap Explanation:
PITFALL
  • Candidates may think course numbering starts at 1 or that empty prerequisites means no courses.
Interviewer Note:
CONTEXT
  • Tests handling of minimal edge case input.
Master "Course Schedule II (Topological 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