Skip to main content
All Visualizers
#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
Time: O(V + E)Space: O(V + E)
Step 1 of 5 • Use Left/Right arrows or Space to control