Critical Path Through Dependent Tasks
Updated
Problem statement
Each task has a unique name, a positive duration, and zero or more prerequisite task names. The dependencies form a directed acyclic graph.
Return a string array whose first value is the maximum total duration of any dependency path and whose remaining values are the task names on that path in execution order. If several paths have the same maximum duration, return the lexicographically smallest task-name sequence.
Function
criticalPathSchedule(taskNames: String[], dependencies: String[][], durations: int[]) → String[]Examples
Example 1
taskNames = ["A","B","C"]dependencies = [[],[],["A"]]durations = [3,5,5]return = ["8","A","C"]The dependent path A to C lasts 8, longer than standalone B.
Example 2
taskNames = ["A","B","C","D","E"]dependencies = [[],["A"],["A"],["B","C"],["D"]]durations = [3,2,7,4,2]return = ["16","A","C","D","E"]The longer branch into D passes through C.
Example 3
taskNames = ["A","B"]dependencies = [[],[]]durations = [4,4]return = ["4","A"]Equal standalone paths use the lexicographically smaller sequence.
Constraints
1 <= taskNames.length == dependencies.length == durations.length <= 200.- Task names are unique nonempty ASCII strings.
- Every dependency names another task, and the graph is acyclic.
1 <= durations[i] <= 100000; every path total fits a signed 32-bit integer.
More Modular Phone Screen questions
Similar questions at other companies
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Work Order Critical PathHadrian · PHONE SCREENHadrian interview questions
- Longest Name Chain in a Directed Acyclic GraphOscar Health · PHONE SCREEN
- Service Dependency Load FactorsRobinhood · PHONE SCREENRobinhood interview questions
- Minimum Time to Complete Target CoursesMeta · ONSITE INTERVIEWMeta interview questions
- Longest Chain BookingAirbnb · PHONE SCREENAirbnb interview questions
- Earliest Dataset Readiness in a PipelinexAI · PHONE SCREENxAI interview questions
- Longest Path in a Directed Acyclic GraphSuno · PHONE SCREEN
- Parallel Courses IIISnowflake · ONSITE INTERVIEWSnowflake interview questions