Minimum Parallel Teams for Project Completion
In large-scale software development, managing complex projects with numerous interdependent tasks is crucial. Efficient resource allocation, specifically the number of parallel teams, directly impacts project timelines and costs. This problem simulates a scenario where you need to determine the minimum number of parallel teams required to complete a project within a strict time limit, respecting all task dependencies.
Implement a function minTeamsForProject that takes the project's details and a time limit, and returns the minimum number of parallel teams needed to complete all tasks within that limit. If it's impossible to complete the project within the given timeLimit even with all tasks running in parallel (i.e., numTasks teams), your function should return -1.
Your solution must:
timeLimit.function minTeamsForProject(numTasks: number, taskDurations: number[], prerequisites: number[][], timeLimit: number): number
numTasks: An integer, the total number of tasks in the project. Tasks are indexed from 0 to numTasks - 1.taskDurations: An array of integers, where taskDurations[i] is the time (in some arbitrary units) required to complete task i.prerequisites: An array of [pre, post] pairs, where pre is a task that must be completed before post can begin. Each pre and post are task indices.timeLimit: An integer, the maximum allowed total time for the entire project to be completed.Returns:
An integer representing the minimum number of parallel teams required. Return -1 if the project cannot be completed within timeLimit under any number of teams (up to numTasks).
prerequisites (the graph is a DAG).numTasks is 0, the function should return 0 teams.Examples
Example 1
Input:
numTasks = 3, taskDurations = [10, 5, 8], prerequisites = [[0, 2], [1, 2]], timeLimit = 20
Output:
2
Note:
Tasks: T0 (10), T1 (5), T2 (8). Dependencies: T0 -> T2, T1 -> T2.
Example 2
Input:
numTasks = 4, taskDurations = [3, 2, 4, 1], prerequisites = [[0, 2], [1, 2], [2, 3]], timeLimit = 10
Output:
1
Note:
Tasks: T0 (3), T1 (2), T2 (4), T3 (1). Dependencies: T0 -> T2, T1 -> T2, T2 -> T3.
Example 3
Input:
numTasks = 2, taskDurations = [100, 1], prerequisites = [[0, 1]], timeLimit = 50
Output:
-1
Note:
Tasks: T0 (100), T1 (1). Dependency: T0 -> T1.
Constraints
0 <= numTasks <= 10^50 <= taskDurations[i] <= 10000 <= prerequisites.length <= 2 * 10^50 <= timeLimit <= 10^9prerequisites[j] contains exactly two elements: [pre, post]0 <= pre, post < numTasksnumTasks = 0, timeLimit = 0, tasks with 0 duration).numTasks up to 10^5 and prerequisites up to 2 * 10^5.Loading editor...