Course Schedule II
There are numCourses courses labeled from 0 to numCourses - 1. You are given prerequisites where prerequisites[i] = [a, b] means you must take course b before course a.
Return an ordering of courses you should take to finish all courses. If impossible, return an empty list.
Output the order as space-separated integers. If multiple valid orderings exist, return any one.
Example
4 1,0;2,0;3,1;3,2
0 1 2 3
- The input
4represents the total number of courses, labeled from0to3. - The prerequisites
1,0;2,0;3,1;3,2indicate that course0is a prerequisite for courses1and2, and courses1and2are prerequisites for course3. - We can start by taking course
0, as it has no prerequisites, then take courses1and2, which both require course0, and finally take course3, which requires both courses1and2. - The resulting ordering is
0 1 2 3, which satisfies all the given prerequisites.
Constraints
- 1 <= numCourses <= 2000
- 0 <= len(prerequisites) <= numCourses * (numCourses - 1)
- All pairs are unique