There are `numCourses` courses labeled `0` to `numCourses - 1`. `prerequisites[i] = [a, b]` means you must take `b` before `a`. Implement `canFinish(numCourses, prerequisites)` returning `true` if you can finish every course, `false` if a cycle makes it impossible. (Asked at Amazon and Google.)
+ 2 hidden tests run on Submit.
Finishing all courses is possible exactly when the prerequisite graph is a DAG. Kahn's algorithm tracks in-degrees, starts from prerequisite-free courses, and peels the graph layer by layer. If the number processed equals `numCourses`, no cycle exists. O(V + E).
Run your code to see results.