Course Schedule II

Med
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Course Schedule II

Approach

Same indegree processing as feasibility check, but store each popped node as part of the output order.

Complexity Analysis

Time
O(V + E)
Space
O(V + E)

Pattern

Topological Order Construction

Why It Works

When a node has zero indegree, all its prerequisites are already in the order. Processing in this sequence ensures constraints are respected.

Updated Feb 2026