Course Schedule I

There are courseCount courses numbered 0 through courseCount - 1. Each pair [course, prerequisite] means the prerequisite must finish before the course.…

There are courseCount courses numbered 0 through courseCount - 1. Each pair [course, prerequisite] means the prerequisite must finish before the course. Return true if every course can be finished, otherwise false. Pairs are unique; the graph may be disconnected or contain a self-loop. With no prerequisites, every course is ready.

- 1 <= courseCount <= 2000 - 0 <= prerequisites.length <= 5000 - Each pair contains two integer IDs from 0 to courseCount - 1 - All ordered prerequisite pairs are unique; self-loops are allowed - The visualizer accepts at most 24 courses and 48 pairs; Run Code and Submit support the full coding domain.

Example 1: input courseCount = 4, prerequisites = [[1,0],[2,1],[3,2]]; output true. Finish courses in order 0, 1, 2, 3; every prerequisite comes first.

Example 2: input courseCount = 4, prerequisites = [[0,1],[3,2],[1,3],[3,0]]; output false. Courses 0, 1 and 3 depend on one another in a cycle. Completing course 2 does not remove that cycle.

Category: Graphs. Topic: graph. Difficulty: Hard. Patterns: graph-traversal, bfs.