 All Problems
Course Schedule II
medium
graph
topological sort
depth-first search
amazon
google
facebook
microsoft

There are a total of numCourses courses labeled 0 to numCourses-1. Given prerequisites, return the ordering of courses you should take to finish all courses. If it is impossible (cycle), return an empty array.

Example 1:

Input:
4 4
1 0
2 0
3 1
3 2
Output: 0 1 2 3

Example 2:

Input:
2 2
1 0
0 1
Output: (empty)

Input format: First line: numCourses numPrereqs. Next numPrereqs lines: "a b".

Output format: Space-separated course order, or empty line if impossible.

Run to check your code against the sample cases, or submit to run every case