#1474Hard· asked at 4 companies
Parallel Courses III
Hosted on LeetCode
Solve it on LeetCode, track it here.
This problem's full statement lives on LeetCode. Open it in a new tab, then come back to mark it solved, add notes and keep your streak.
LeetCode Premium locked?
Most company-tagged LeetCode problems are behind Premium. If you have ChatGPT Plus or Claude Pro, ask it for the full statement, examples and constraints. The buttons below open a chat with the prompt already filled in.
What we know
Example 1
Input: n = 3, relations = [[1,3],[2,3]], time = [3,2,5] Output: 8
Take courses 1 and 2 in parallel (3 months), then course 3 (5 months).
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) - •
1 <= time[i] <= 10^4 - •
The given graph is a directed acyclic graph.