LESSON 08 OF 08Topological sort
0% learnt
COURSE SCHEDULE · KAHN’S TOPOLOGICAL SORT
Which courses can enter the queue first?
A and B have no incoming prerequisite edges. Every other course is still blocked.
RULE TO APPLYOnly indegree 0 is ready; removing a course decreases the indegree of what it unlocks.
LIVE ALGORITHM STATEThe badge on each course is its remaining prerequisite count.
READY QUEUE · INDEGREE 0
AB
LESSON 081 / 2
REAL INTERVIEW PROBLEMTake every course only after its prerequisites.
Given courses and directed prerequisite edges, return a valid order or report that no order exists because of a cycle.
INPUTA→C, B→C, C→D, D→EOUTPUT[A, B, C, D, E]
WHAT YOU WILL DOChoose only zero-indegree courses, remove their outgoing edges, and enqueue each course when its final prerequisite disappears.