⚡️ Tryprepforge
Coding Round 2 Mid-Level programming

**LeetCode #207 - Course Schedule**\nYou are given an integer numCourses representing the total number of courses you have to take, labeled from `0` to `numCourses - 1`. You are also given an array `prerequisites`, where `prerequisites[i] = [a_i, b_i]` indicates that you must take course `b_i` before course `a_i`. Return `true` if you can finish all courses. This requires detecting cycles in a directed graph using DFS or Kahn's algorithm.\n**Function Signature:** `def can_finish(numCourses: int, prerequisites: List[List[int]]) -> bool:`\n**Example 1:**\nInput: `numCourses = 2, prerequisites = [[1, 0]]`\nOutput: `true`\nExplanation: There are no cycles so you can take the courses.\n**Example 2:**\nInput: `numCourses = 2, prerequisites = [[1, 0], [0, 1]]`\nOutput: `false`\nExplanation: There is a cycle in the prerequisites.\n**Constraints:**\n- `1 <= numCourses <= 2000`\n- `0 <= prerequisites.length <= 5000`\n- `prerequisites[i].length == 2`.

Suggested Answer

Practice More Questions Like This

Generate unlimited interview questions with structured answers, code runner, and AI-powered walkthroughs.

No credit card required

More Coding Round 2 Interview Prep

Link copied to clipboard