Parallel Courses III
Updated
Problem statement
You are given n courses numbered from 1 to n. Each relation [prevCourse, nextCourse] means that prevCourse must be completed before nextCourse can begin.
The array time is zero-indexed, and time[i] is the number of months needed to complete course i + 1. You may begin any number of courses at the same time once all of their prerequisites are complete.
Return the minimum number of months needed to complete all courses.
Function
minimumCourseCompletionTime(n: int, relations: int[][], time: int[]) → intExamples
Example 1
n = 3relations = [[1,3],[2,3]]time = [3,2,5]return = 8Courses 1 and 2 start together. Course 3 starts after month 3 and finishes five months later.
Example 2
n = 5relations = [[1,5],[2,5],[3,5],[3,4],[4,5]]time = [1,2,3,4,5]return = 12The critical prerequisite chain is course 3, then course 4, then course 5, requiring 3 + 4 + 5 = 12 months.
Example 3
n = 2relations = []time = [4,7]return = 7With no prerequisites, both courses run in parallel, so completion is determined by the slower course.
Constraints
1 <= n <= 50000.0 <= relations.length <= 50000.relations[i].length == 2.1 <= prevCourse, nextCourse <= n.- The prerequisite graph is a directed acyclic graph.
time.length == n.1 <= time[i] <= 10000.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREEN
- Parallel Courses IIISnowflake · ONSITE INTERVIEW
- Minimum Semesters With Course CapacityAmazon · ONSITE INTERVIEW
- Letter Order from a Sorted Word ListRippling · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Time to Complete Target CoursesMeta · ONSITE INTERVIEW
- Cheapest Flights Within K StopsGoldman Sachs · ONSITE INTERVIEW
- Critical Path Through Dependent TasksModular · PHONE SCREEN · ONSITE INTERVIEW
- Largest Consistent Visiting GroupAuxoAI · OA
- Choose a Road to Maximize Average Route Toll IncreaseHarness · PHONE SCREEN
- Parallel Courses with DurationsCitadel · PHONE SCREEN