Loading problem…
This problem builds on course-schedule. Complete that first, then load your solution to continue.
There are numCourses courses labeled 0 through numCourses - 1. Each pair [course, prerequisite] means the prerequisite must be completed before that course.
Return an ordering containing every course exactly once that satisfies all dependencies. If several orderings work, return any of them. Return [] if a cycle makes completion impossible. Include courses without prerequisites and isolated courses. Unlike Course Schedule, this variant must construct a valid order rather than return a boolean.
Example 1:
Example 2:
Example 3: