Trains the technique from
LeetCode 2050Parallel Courses IIIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A refinery shutdown is broken into stages jobs numbered 1 through stages. Job i occupies hours[i - 1] hours from the moment it starts and runs straight through to its finish.
precedes[j] = [a, b] records that job a has to be finished before job b may begin. Each ordered pair appears at most once and the pairs never close a loop.
The crew is large enough that any number of jobs may run side by side, and a job begins at the very moment the last job it waits on has finished. A job with nothing ahead of it begins at hour 0.
Return the number of hours from hour 0 until the final job finishes.
Example 1
Job 1 runs from hour 0 to hour 2. Jobs 2 and 3 both begin at hour 2 and finish at hours 5 and 8. Job 4 waits on both of them, so it begins at hour 8 and finishes at hour 9.
Example 2
Nothing waits on anything, so all five jobs begin at hour 0 and job 5 is the last to finish, at hour 5.
Example 3
Job 1 runs from hour 0 to hour 5 and job 2 follows from hour 5 to hour 6. Job 3 waits on nothing, so it runs from hour 0 to hour 9.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def shutdown_span(stages: int, precedes: list[list[int]], hours: list[int]) -> int:public int shutdownSpan(int stages, int[][] precedes, int[] hours)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.