Course Schedule II

Given courseCount courses numbered 0 through courseCount-1 and unique prerequisite pairs [course, prerequisite], return any ordering that finishes every…

Given courseCount courses numbered 0 through courseCount-1 and unique prerequisite pairs [course, prerequisite], return any ordering that finishes every course. Each prerequisite must appear before its course. Include courses without dependencies. Return an empty array if a cycle makes a full schedule impossible; a partial schedule is not an answer.

- 1 <= courseCount <= 2000 - 0 <= prerequisites.length <= 5000 - Each pair contains two integer course IDs in 0..courseCount-1 - All pairs are unique; self-dependencies are valid cyclic inputs - The visualizer accepts at most 24 courses and 48 pairs; larger valid inputs remain execution-only

Example 1: input courseCount = 4, prerequisites = [[1,0],[2,1],[3,2]]; output [0,1,2,3]. Finish 0 before 1, then 2, then 3.

Example 2: input courseCount = 4, prerequisites = [[0,1],[3,2],[1,3],[3,0]]; output []. Dependencies 3 to 1 to 0 to 3 form a cycle, so no full schedule exists.

Category: Graphs. Topic: graph. Difficulty: Medium. Patterns: graph-traversal.