course_count courses numbered from 1 to course_count. Course i takes durations[i - 1] months.
Some courses can only start after others: a pair [a, b] in prereqs means course a must be finished before course b begins.
A course can start at any moment once all the courses it depends on are done, and any number of courses can run at the same time.
Return the minimum number of months needed to finish the whole program. The dependencies contain no cycles.course_count=4, prereqs=[[1, 2], [1, 3], [3, 4]], durations=[2, 6, 1, 3] → 8
Course 1 ends after 2 months. Course 2 follows it and ends at 2 + 6 = 8. Courses 3 and 4 end at 2 + 1 + 3 = 6. Everything is done after 8 months.
course_count=3, prereqs=[], durations=[4, 9, 2] → 9
There are no dependencies, so all courses run at once and we wait for the longest one: 9 months.
course_count=3, prereqs=[[2, 1], [3, 1]], durations=[5, 1, 4] → 9
prereqs are distinct and the dependencies form no cyclecourse_count=4, prereqs=[[1, 2], [1, 3], [3, 4]], durations=[2, 6, 1, 3]
8
Run checks the first 3 tests in your browser. Submit checks all 63 tests on the server, hidden ones included.