Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

149. Course Schedule II

MediumDay 44 of 60Graphs

There are numCourses courses labelled 0 to numCourses - 1, and prerequisites[i] = [a, b] means course b must be taken before course a. Return any order in which you can take all the courses. If it is impossible, return an empty array.

Example 1
Input: numCourses = 2, prerequisites = [[1,0]]
Output: [0,1]
Example 2
Input: numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]]
Output: [0,1,2,3]
[0,2,1,3] is also accepted.
Constraints
  • 1 <= numCourses <= 2000
  • 0 <= prerequisites.length <= numCourses * (numCourses - 1)
  • All pairs are distinct
Hints
Frequently asked at: Amazon, Microsoft, Google, Meta
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min