Minimum Time to Complete Target Courses
Updated
Problem statement
There are n courses labeled from 0 through n - 1. Course i takes durations[i] time units.
Each pair [course, prerequisite] in prerequisites means the prerequisite must finish before the course can start. The prerequisite graph is acyclic.
You may take any number of available courses in parallel. Return the minimum time needed to finish every course in targets, including every transitive prerequisite needed by those targets. Courses outside that required closure do not affect the answer.
Function
minimumTimeForTargets(durations: int[], prerequisites: int[][], targets: int[]) → longExamples
Example 1
durations = [3,2,5]prerequisites = [[2,0],[2,1]]targets = [2]return = 8Courses 0 and 1 run in parallel. Course 2 starts at time 3 and finishes at time 8.
Example 2
durations = [2,4,3,7]prerequisites = [[1,0],[2,0]]targets = [1,2]return = 6After course 0 finishes at time 2, courses 1 and 2 run together. The slower target finishes at time 6. Disconnected course 3 is irrelevant.
Example 3
durations = [5,1,2]prerequisites = []targets = [1,2]return = 2With no prerequisites, both targets start immediately and the later one finishes after 2 time units.
Constraints
1 <= durations.length <= 100000.1 <= durations[i] <= 10^9.0 <= prerequisites.length <= 200000.- Every prerequisite pair contains distinct valid course labels, all pairs are unique, and the graph is acyclic.
1 <= targets.length <= durations.length, and target labels are unique.- The answer fits a signed 64-bit integer.
More Meta Onsite Interview questions
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
- Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
- Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
- Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
- Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
- Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Critical Path Through Dependent TasksModular · PHONE SCREEN · ONSITE INTERVIEW
- Parallel Courses IIISnowflake · ONSITE INTERVIEWSnowflake interview questions
- Parallel Courses IIIGoogle · ONSITE INTERVIEWGoogle interview questions
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- 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
- Longest Chain BookingAirbnb · PHONE SCREENAirbnb interview questions
- Earliest Dataset Readiness in a PipelinexAI · PHONE SCREENxAI interview questions