115. Minimum Time to Finish the Tasks
Medium
A project consists of tasks that can run in parallel with an unlimited number of people. Task i takes duracoes[i] units of time to complete.
Each pair [a, b] in dependencias means task a must finish before task b can start. A task with no prerequisites may start at time zero.
Return the minimum time needed to finish all tasks. The dependencies are guaranteed to contain no cycles.
Example 1
Input: duracoes = [3, 2, 5], dependencias = [[0, 2], [1, 2]]
Output: 8
Explanation: Tasks 0 and 1 start together; task 2 starts when task 0 finishes.
Example 2
Input: duracoes = [4, 1, 3], dependencias = [[0, 1], [1, 2]]
Output: 8
Explanation: The three tasks form a chain, so their durations are added.
Example 3
Input: duracoes = [2, 7, 1], dependencias = []
Output: 7
Explanation: With no dependencies, all tasks start together.
Constraints
- 1 <= duracoes.length <= 100000
- 1 <= duracoes[i] <= 1000000000
- 0 <= dependencias.length <= 200000
- Each element of dependencias has the form [a, b], where 0 <= a, b < duracoes.length and a != b.
- The dependencies contain no cycles; repeated pairs are allowed.
GraphsDynamic programming
Saved in this browser
Caso 1
duracoes =
[3,2,5]
dependencias =
[[0,2],[1,2]]
Expected =
8
Caso 2
duracoes =
[4,1,3]
dependencias =
[[0,1],[1,2]]
Expected =
8
Caso 3
duracoes =
[2,7,1]
dependencias =
[]
Expected =
7
Run checks these 3 cases. Submit runs all 12, including hidden ones.