Parallel Courses with Durations
Updated
Problem statement
Given an integer n, a 2D integer array relations and an integer array time, return the minimum number of months needed to finish all n courses, or -1 if that is impossible.
The courses are labeled from 1 to n, and course i takes time[i - 1] months. Each relations[j] = [prevCourse, nextCourse] means that course prevCourse must be finished before course nextCourse can start.
A course can start as soon as all of its prerequisites are finished. A course with no prerequisites can start at month 0. You can take any number of courses at the same time.
If the prerequisites contain a cycle, the courses on that cycle can never start, so the answer is -1.
Function
minimumTime(n: int, relations: int[][], time: int[]) → intExamples
Example 1
n = 5relations = [[1,3],[2,3],[3,5],[2,4]]time = [3,2,6,1,4]return = 13Courses 1 and 2 start at month 0 and finish at months 3 and 2. Course 3 needs both, so it runs from month 3 to month 9, and course 5 then runs from month 9 to month 13. Course 4 runs from month 2 to month 3, while course 1 is still running.
Example 2
n = 4relations = [[1,2],[2,3],[3,4],[4,2]]time = [2,3,1,4]return = -1Course 2 needs course 4, course 4 needs course 3, and course 3 needs course 2. These three courses wait for each other in a cycle, so none of them can ever start.
Example 3
n = 4relations = [[1,2],[2,3]]time = [2,2,2,9]return = 9The chain 1, 2, 3 takes 6 months. Course 4 has no prerequisites, so it runs at the same time and takes 9 months, which is longer.
Constraints
1 <= n <= 10^40 <= relations.length <= 2 * 10^4relations[j].length == 21 <= prevCourse, nextCourse <= nprevCourse != nextCourse- All the pairs [prevCourse, nextCourse] are unique.
time.length == n1 <= time[i] <= 10^4
More Citadel Phone Screen questions
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
- Merge Price-Delta FeedsPHONE SCREEN · Seen Sep 2026
- Reconcile Unmatched Trades with Timestamp TolerancePHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
- Choose a Road to Maximize Average Route Toll IncreaseHarness · PHONE SCREEN
- 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
- Longest Chain BookingAirbnb · PHONE SCREENAirbnb interview questions
- Critical Path Through Dependent TasksModular · PHONE SCREEN · ONSITE INTERVIEW
- Earliest Dataset Readiness in a PipelinexAI · PHONE SCREENxAI interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences