Practice Parallel Courses III
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
relations contains [prerequisite,nextCourse] for courses 1 through n, and time[i] is the duration of course i + 1. A course may begin as soon as all prerequisites finish, and any number may run concurrently. The dependency graph is acyclic. Return the least time needed to finish every course.
Source: Parallel Courses III on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
n = 3, relations = [[1,3],[2,3]], time = [3,2,5]
Output
8
# Example 2
Input
n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]
Output
12
Constraints
1 <= n <= 5 * 10^4
0 <= relations.length <= min(n * (n - 1) / 2, 5 * 10^4)
relations[j].length == 2
1 <= prevCoursej, nextCoursej <= n
prevCoursej != nextCoursej
All the pairs [prevCoursej, nextCoursej] are unique.
time.length == n
1 <= time[i] <= 10^4
The given graph is a directed acyclic graph.
Related LeetCode Problems
Practice more problems similar to Parallel Courses III.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.