Work Order Critical Path
Problem statement
A work order contains operations in a directed acyclic graph. Each operation has a unique identifier, a type label, and a positive duration in days. dependencies[i] lists the operation identifiers that must finish before operationIds[i] can start.
Every maximal dependency path ends at the operation named by shippingId. Return the maximum total duration along any dependency path that ends at shipping, including the shipping operation itself.
The type labels are descriptive metadata and do not change scheduling behavior.
Function
criticalPathDuration(operationIds: String[], operationTypes: String[], dependencies: String[][], durations: int[], shippingId: String) → intExamples
Example 1
operationIds = ["cut","paint","inspect","ship"]operationTypes = ["FAB","FINISH","QA","SHIP"]dependencies = [[],["cut"],["paint"],["inspect"]]durations = [2,4,1,1]shippingId = "ship"return = 8The only path to shipping lasts 2 + 4 + 1 + 1 = 8 days.
Example 2
operationIds = ["a","b","c","ship"]operationTypes = ["FAB","FAB","QA","SHIP"]dependencies = [[],[],["a"],["b","c"]]durations = [5,9,3,2]shippingId = "ship"return = 11The branch b to ship lasts 11 days, longer than the a-to-c branch at 10 days.
Constraints
1 <= operationIds.length == operationTypes.length == dependencies.length == durations.length <= 500.- Operation identifiers are unique nonempty ASCII strings, and
shippingIdnames one operation. - Every dependency names another operation, the graph is acyclic, and every maximal path ends at shipping.
1 <= durations[i] <= 100000; the answer fits a signed 32-bit integer.