CodeOath
← All problems

Course Schedule

Medium
graphstopological-sort

There are numCourses courses labeled 0 to numCourses - 1. You're given prerequisites, an array of [course, prereq] pairs meaning you must take prereq before course.

Return true if it's possible to finish all courses (i.e., the prerequisite graph has no cycle), otherwise false.

Example:

Input: numCourses = 2, prerequisites = [[1,0]]
Output: true

Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
Output: false