Course Schedule
Medium Advanced graphs AI round
There are numCourses courses, numbered from 0 to numCourses - 1. Each pair [a, b] in prerequisites says that course b has to be finished before course a can be started.
You take the courses one at a time, and finish each one before starting the next. A course can be started only when every course its pairs put before it has been finished.
Return true if every course can be finished in some order, and false if it cannot.
Example 1
Take the courses in the order 0, 1, 2, 3: when each one comes up, the one it waits for has been finished.
Example 2
Course 0 waits for 1, which waits for 2, which waits for 0: they wait for each other in a circle, so none of them can ever start.
Example 3
Constraints
1 ≤ numCourses ≤ 10⁵0 ≤ prerequisites.length ≤ 10⁵- Every pair has two courses,
aandb, with0 ≤ a, b < numCourses aandbmay be the same course, and a pair may appear more than once
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
Your first AI round is free.
Watch the explanation
More Advanced graphs
- Cheapest Flights Within K StopsAI round · Medium
- Longest Increasing Path in a MatrixAI round · Hard
- Alien DictionaryHard
- Course Schedule IIMedium
- Evaluate DivisionMedium