Course Schedule II

Try to solve the Course Schedule II problem.

Statement

Let’s assume that there are a total of nn courses labeled from 00 to n−1n-1. Some courses may have prerequisites. A list of prerequisites is specified such that if Prerequisitesi=a,bPrerequisites_i = {a, b}, you must take course bb before course aa.

Given the total number of courses nn and a list of the prerequisite pairs, return the course order a student should take to finish all of the courses. If there are multiple valid orderings of courses, then the return any one of them.

Note: There can be a course in the 00 to n−1n-1 range with no prerequisites.

Constraints:

Let nn be the number of courses.

  • 1≤n≤15001 \leq n \leq 1500
  • 0≤0 \leq prerequisites.length ≤1000\leq 1000
  • prerequisites[i].length ==2== 2
  • 0≤a, b<n0 \leq a, \space b < n
  • a≠ba \neq b
  • All the pairs [a, b][a, \space b] are distinct.

Examples

Create a free account to view this lesson.

By signing up, you agree to Educative's Terms of Service and Privacy Policy