Course Schedule: Cycle Detection in Directed Graph
Problem Statement
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] = [a, b]` indicates that you must take course `b` first if you want to take course `a`.
Return `true` if you can finish all courses. Otherwise, return `false`.
### Input Format
- First line contains an integer `numCourses`.
- Second line contains an integer `m` (number of prerequisite pairs).
- The next `m` lines each contain two integers `a b`.
### Output Format
- Print `true` or `false`.
### Constraints
- `1 <= numCourses <= 2000`
- `0 <= prerequisites.length <= 5000`
Sample Cases
Example 1Sample Case
Input: 2
1
1 0
Output: true
Example 2Sample Case
Input: 2
2
1 0
0 1
Output: false
Example 3Sample Case
Input: 1 0
1
2
Output: true
Constraints
Runtime Limit: 2000 ms per test batch
Memory Limit: 256 MB
Standard I/O stream reading
Official submissions are evaluated against hidden test cases on the server to verify time & memory complexity.