Course Schedule

Medium Solved

Description

There are numCourses courses you have to take, labeled from 0 to numCourses - 1.

Some courses have prerequisites. prerequisites[i] = [a, b] means you must take course b before course a.

Return true if you can finish all courses. Otherwise, return false.

Input format:

  • Line 1: Integer numCourses
  • Line 2: Prerequisites as JSON array

Examples

Input:

2 [[1,0]]

Output: true

Input:

2 [[1,0],[0,1]]

Output: false

Note:

Print only true or false.

No submissions yet.

Discuss graph cycles, topological sorting, DFS vs BFS (Kahn’s Algorithm).

Test Cases