Earliest finish for dependent tasks
A build has tasks numbered 0 to n - 1; task i takes durations[i] minutes. Each pair [task, needs] in deps means task can only start after needs has finished. Any number of tasks can run at the same time. Return the earliest minute at which every task is finished, or -1 if the dependencies form a cycle.
Durations are positive, pairs may repeat, and with no tasks the answer is 0.
Besides the tests, one large input (3,500 tasks in a chain) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
earliest_finish([3,2,4], [[2,0],[2,1]])→7earliest_finish([5,1,1], [[2,1]])→5earliest_finish([2,2], [[0,1],[1,0]])→-1