call(back)
Algorithms & Data Structuresmedium

Course Schedule

There are n courses labeled 0 to n-1, and a list of prerequisite pairs [a, b] meaning you must take course b before course a. Determine whether it is possible to finish all courses.

Follow-up: when it is possible, return one valid ordering (topological sort).

Asked at