Course Schedule
There are numCourses courses labeled 0..numCourses-1. Given a list prerequisites where [a, b] means you must take course b before course a, decide whether you can finish all courses. This is possible exactly when the prerequisite graph has no cycle.
Open official problem prompt ↗Decide whether a set of ordering constraints is mutually satisfiable, i.e. whether the dependency graph can be linearized with no course depending (directly or transitively) on itself.
Think of assembling furniture: each step lists what must already be built. If two steps each secretly require the other, you can never start; otherwise you can always find some step whose prerequisites are all done.
- Input
- numCourses = 2, prerequisites = [[1, 0]]
- Output
- true
- Why
- Take course 0 first, then course 1; there is no circular dependency.
1 <= numCourses <= 20000 <= prerequisites.length <= 5000prerequisites[i].length == 20 <= a_i, b_i < numCoursesAll prerequisite pairs are distinct