Course Schedule

Medium · Graphs · Graph · Topological Sort · DFS · BFS

Problem

There are numCourses courses labelled 0 to numCourses - 1. Each pair [a, b] in prerequisites means b must be taken before a.

Return whether every course can be completed.

Examples

Input: numCourses = 2, prerequisites = [[1,0]]
Output: True

Take 0, then 1.

Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
Output: False

Each needs the other first — a cycle.

Constraints

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…