FastPrepWork Order Critical Path

Work Order Critical Path

Hadrian logoHadrian● MediumFULLTIMEPHONE SCREEN
Learn

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) → int

Examples

Example 1

operationIds = ["cut","paint","inspect","ship"]operationTypes = ["FAB","FINISH","QA","SHIP"]dependencies = [[],["cut"],["paint"],["inspect"]]durations = [2,4,1,1]shippingId = "ship"return = 8

The 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 = 11

The 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 shippingId names 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.

More Hadrian problems

See Hadrian hiring insights
public int criticalPathDuration(String[] operationIds, String[] operationTypes, String[][] dependencies, int[] durations, String shippingId) {
    // Write your code here.
}
operationIds["cut","paint","inspect","ship"]
operationTypes["FAB","FINISH","QA","SHIP"]
dependencies[[],["cut"],["paint"],["inspect"]]
durations[2,4,1,1]
shippingId"ship"
expected8
Checking account…