#LC 207•Graphs•Medium
Course Schedule
Given courses and prerequisite pairs, decide whether all courses can be completed without a dependency cycle.
Understand the problem
Given courses and prerequisite pairs, decide whether all courses can be completed without a dependency cycle.
Example 1
Input: {"numCourses": 4, "prerequisites": [[1, 0], [2, 0], [3, 1], [3, 2]]}
Output: true
Follow the trace to see how the algorithm reaches this result.
Constraints
- Use the input format shown in the example.
Think first
What information should you keep so you can solve the next step efficiently?
Pattern tags:GraphTopological sortBFS