Problem · Graph
Course Schedule
Learn this problemProblem statement
There are numCourses courses labeled from 0 to numCourses - 1. Each pair [course, prerequisite] means the prerequisite must be completed before the course.
Return true if all courses can be completed, or false if the prerequisite graph contains a cycle.
Interview Follow-up
The interviewer asked follow-up questions about alternative solutions, edge cases, and complexity analysis.
Function
canFinish(numCourses: int, prerequisites: int[][]) → booleanExamples
Example 1
numCourses = 2prerequisites = [[1,0]]return = trueExample 2
numCourses = 2prerequisites = [[1,0],[0,1]]return = falseEach course requires the other first, creating a cycle.