count courses numbered 1 to count. A pair [a, b] in prereqs means course a must be completed before course b can be taken. The prerequisites contain no cycles.
In one term you can take at most load courses, and all of their prerequisites must have been completed in earlier terms.
Return the minimum number of terms needed to complete every course.count=5, prereqs=[[1, 3], [2, 3], [3, 4], [3, 5]], load=2 → 3
Term 1: courses 1 and 2. Term 2: course 3. Term 3: courses 4 and 5.
count=6, prereqs=[[1, 2], [2, 3]], load=2 → 3
The chain 1 → 2 → 3 needs three terms, so course 1 must be taken right away: 1 and 4, then 2 and 5, then 3 and 6. Starting with 4 and 5 would take four terms.
count=4, prereqs=[], load=4 → 1
There are no prerequisites, and all four courses fit into one term.
prereqs are distinctcount=5, prereqs=[[1, 3], [2, 3], [3, 4], [3, 5]], load=2
3
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.