Coding Round 2
Mid
programming
LeetCode #207 - Course Schedule
You are given
Input:
Output:
Explanation: There are a total of 2 courses that can be finished without dependency issues.Example 2:
Input:
Output:
Explanation: A cycle exists which makes it impossible to complete the courses.Constraints:
numCourses courses and an array of prerequisite pairs prerequisites. Each pair prerequisites represents a directed edge where you need to finish course a before course b. Determine if you can finish all courses using a topological sort approach. If it is not possible to complete all courses (due to circular dependency), return false.Example 1:Input:
numCourses = 2, prerequisites = [[1,0]]Output:
trueExplanation: There are a total of 2 courses that can be finished without dependency issues.Example 2:
Input:
numCourses = 2, prerequisites = [[1,0], [0,1]]Output:
falseExplanation: A cycle exists which makes it impossible to complete the courses.Constraints:
0 <= numCourses <= 20000 <= prerequisites.length <= 5000prerequisites[i].length == 2.
Suggested Answer