From 7d57faa958ec0cee9d7e5fdc82b3dec8a12d1c84 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Tue, 22 Sep 2026 13:01:22 -0400 Subject: [PATCH] feat(work): add solution stub for Course Schedule (207) --- .../topological-sort/207-course-schedule.mdx | 34 ++++++++++++ apps/docs/content/topological-sort/meta.ts | 3 ++ .../Depth-First Search/207.course-schedule.py | 52 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 apps/docs/content/topological-sort/207-course-schedule.mdx create mode 100644 apps/docs/content/topological-sort/meta.ts create mode 100644 work/1/Medium/Depth-First Search/207.course-schedule.py diff --git a/apps/docs/content/topological-sort/207-course-schedule.mdx b/apps/docs/content/topological-sort/207-course-schedule.mdx new file mode 100644 index 0000000..1c51120 --- /dev/null +++ b/apps/docs/content/topological-sort/207-course-schedule.mdx @@ -0,0 +1,34 @@ +--- +title: '207. Course Schedule' +description: There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai +sidebar: + label: 'Course Schedule' + badge: 'Medium' +--- + +Depth-First Search + +### Example 1: +- Input: `numCourses = 2, prerequisites = [[1,0]]` +- Output: `true` +- Explanation: There are a total of `2` courses to take. To take course `1` you should have finished course `0`. So it is possible. + +### Example 2: +- Input: `numCourses = 2, prerequisites = [[1,0],[0,1]]` +- Output: `false` +- Explanation: There are a total of `2` courses to take. To take course `1` you should have finished course `0`, and to take course `0` you should also have finished course `1`. So it is impossible. + +### Constraints: + +- `1 <= numCourses <= 2000` +- `0 <= prerequisites.length <= 5000` +- `prerequisites[i].length == 2` +- `0 <= ai, bi < numCourses` +- All the pairs `prerequisites[i]` are unique. + +## Solution + +```py +class Solution: + def canFinish(self, numCourses: int, prerequisites: list[list[int]]) -> bool: +``` diff --git a/apps/docs/content/topological-sort/meta.ts b/apps/docs/content/topological-sort/meta.ts new file mode 100644 index 0000000..b560581 --- /dev/null +++ b/apps/docs/content/topological-sort/meta.ts @@ -0,0 +1,3 @@ +import { defineMeta } from "blume"; + +export default defineMeta({ title: "Topological Sort", order: 18 }); diff --git a/work/1/Medium/Depth-First Search/207.course-schedule.py b/work/1/Medium/Depth-First Search/207.course-schedule.py new file mode 100644 index 0000000..c617af0 --- /dev/null +++ b/work/1/Medium/Depth-First Search/207.course-schedule.py @@ -0,0 +1,52 @@ +""" +207. Course Schedule +Difficulty: Medium +https://leetcode.com/problems/course-schedule/ + +────────────────────────────────────────────────── + +There are a total of numCourses courses you have to take, labeled +from 0 to numCourses - 1. You are given an array prerequisites where +prerequisites[i] = [ai, bi] indicates that you must take course bi +first if you want to take course ai. + +• For example, the pair [0, 1], indicates that to take course 0 you +have to first take course 1. + +Return true if you can finish all courses. Otherwise, return false. + + + +Example 1: + +Input: numCourses = 2, prerequisites = [[1,0]] +Output: true +Explanation: There are a total of 2 courses to take. +To take course 1 you should have finished course 0. So it is possible. + +Example 2: + +Input: numCourses = 2, prerequisites = [[1,0],[0,1]] +Output: false +Explanation: There are a total of 2 courses to take. +To take course 1 you should have finished course 0, and to take +course 0 you should also have finished course 1. So it is impossible. + + + +Constraints: + + • 1 <= numCourses <= 2000 + + • 0 <= prerequisites.length <= 5000 + + • prerequisites[i].length == 2 + + • 0 <= ai, bi < numCourses + + • All the pairs prerequisites[i] are unique. +""" + +class Solution: + def canFinish(self, numCourses: int, prerequisites: list[list[int]]) -> bool: +