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

148. Course Schedule

MediumDay 44 of 60Graphs

There are numCourses courses labelled 0 to numCourses - 1. Each pair prerequisites[i] = [a, b] means you must finish course b before course a. Return true if it is possible to finish every course, otherwise false.

Example 1
Input: numCourses = 2, prerequisites = [[1,0]]
Output: true
Take course 0, then course 1.
Example 2
Input: numCourses = 2, prerequisites = [[1,0],[0,1]]
Output: false
Each course needs the other first: a cycle.
Constraints
  • 1 <= numCourses <= 2000
  • 0 <= prerequisites.length <= 5000
  • prerequisites[i] = [a, b] with 0 <= a, b < numCourses
  • All pairs are distinct
Hints
Frequently asked at: Amazon, Microsoft, Google, Uber, 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