Can you finish every course?
Mediumgraphtopological sortbfs
There are n courses numbered 0 to n - 1. Each [a, b] in prereqs means you must finish b before a (like JavaScript before React). Return true if it's possible to finish every course.
Example 1
Input: n = 2, prereqs = [[1,0]] Output: true
Example 2
Input: n = 2, prereqs = [[1,0],[0,1]] Output: false
Each course waits for the other: a cycle.
Constraints
- 1 ≤ n ≤ 2000
- 0 ≤ prereqs.length ≤ 5000
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {int} n
* @param {int[][]} prereqs
* @return {bool}
*/
function canFinish(n, prereqs) {
}