Leetcode 210 Course Schedule II Python 3 Solution
Approach - We will first create a graph out of this problem, Every pre-requisite course is connected to the course so the Pre=requisite course will be directing towards the course so we will create a Directed Acyclic Graph. We will find if there is any cycle in the graph and if it is so then taking all the courses will not be possible. To find if there is any cycle in the graph we will use an earlier discussed approach we took in Course Schedule I. We will use Topological Sort to get the order in which we need to take the course so that we take all the pre-requisites before the courses. If you have any doubt just let me know in the comments.
|
|