Graph Theory37 sections · 1633 units
Open in Course

Problem - Course Schedule

(LeetCode 207 prerequisites)

You have N courses (00 to N1N-1) and a list of prerequisites. For example, [00, 11] means you must take course 11 before course 00.

Return true if you can finish all courses, false if impossible.

Think: what makes it impossible to finish all courses? If course A requires B and B requires A, you have a circular dependency. No valid ordering exists. This is asking you to detect whether a directed graph contains a cycle. The graph has courses as nodes and prerequisites as directed edges.