103. Course Schedule — Feasibility
A pair identifies a course and another course that must be taken first. Decide whether there is some way to finish all courses while obeying all prerequisite relationships.
The order of the pair matters. A cycle of prerequisites makes completion impossible, while courses with no prerequisites still need to be included.
Example 1
Input
numCourses=2, prerequisites=[[1,0]]
Output
true
Explanation: Finish 0, then 1.
Example 2
Input
numCourses=2, prerequisites=[[1,0],[0,1]]
Output
false
Explanation: Each course waits for the other.
Example 3
Input
numCourses=3, prerequisites=[[1,0],[1,0]]
Output
true
Explanation: Both parallel edges are removed when course 0 finishes; course 2 is independent.
Constraints
0 <= numCourses <= 1050 <= edge occurrences <= 2 * 1050 <= vertex label < numCourses
Hints
Hint 1
Which courses can be taken before any others?
Hint 2
After taking one, which unmet counts change?
Hint 3
Repeatedly remove zero-indegree courses; success requires removing every vertex.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Parallel edges and an isolated course
3
[[1,0],[1,0]]
true