Coding Round 2
Senior
programming
LeetCode #207 - Course Schedule
You are given a number of courses you have to take, and can take course prerequisites as a directed graph. You need to determine if it's possible to finish all courses if prerequisites are given in pairs. This assesses your grasp on graph algorithms and cycle detection methods.Function Signature:
Example 2:
Constraints:
def can_finish(num_courses: int, prerequisites: List[List[int]]) -> bool:Example 1:- Input:
num_courses = 2, prerequisites = [[1,0]] - Output:
True - Explanation: You can take course 0 first, then course 1.
Example 2:
- Input:
num_courses = 2, prerequisites = [[1,0],[0,1]] - Output:
False - Explanation: There is a cycle in the prerequisites.
Constraints:
1 <= num_courses <= 20000 <= prerequisites.length <= 5000prerequisites[i].length == 2.
Suggested Answer