Finish Order and Total Time for Dependent Tasks
Updated
Problem statement
You are given a list of tasks tasks, where tasks[i] = [taskId, duration], and a list of rules dependencies, where dependencies[j] = [before, after] means task before must finish before task after can start.
Tasks never block each other: when several tasks are ready, they all run together. Every task starts as soon as all of its prerequisites have finished, or at time 0 if it has none. A task that starts at time s finishes at time s + duration.
Return an array whose first value is the total time, meaning the time when the last task finishes, followed by every task ID in the order the tasks finish. When several tasks finish at the same time, list the smaller ID first.
If the dependencies form a cycle, so that some tasks can never start, return an empty array.
Function
totalTimeAndOrder(tasks: int[][], dependencies: int[][]) → int[]Examples
Example 1
tasks = [[6,5],[8,1],[3,3],[2,2]]dependencies = [[8,3],[6,2],[3,2]]return = [7,8,3,6,2]Tasks 6 and 8 have no prerequisites, so both start at time 0. Task 8 finishes at 1 and task 6 at 5. Task 3 waits for task 8, so it runs from 1 to 1 + 3 = 4. Task 2 waits for tasks 6 and 3; the later of the two is task 6 at 5, so task 2 runs from 5 to 5 + 2 = 7. The finish order is 8, 3, 6, 2 and everything is done at time 7.
Example 2
tasks = [[30,2],[10,2],[20,1],[40,3]]dependencies = [[20,40]]return = [4,20,10,30,40]Tasks 30, 10 and 20 start at time 0. Task 20 finishes at 1, so task 40 starts at 1 and finishes at 4. Tasks 10 and 30 both finish at time 2; the smaller ID, 10, comes first. The answer is the total time 4 followed by 20, 10, 30, 40.
Example 3
tasks = [[1,5],[2,1],[3,2]]dependencies = [[1,2],[2,1]]return = []Task 1 must finish before task 2, and task 2 must finish before task 1. Neither can ever start, so no schedule exists and the answer is an empty array, even though task 3 alone could run.
Constraints
1 <= tasks.length <= 1000tasks[i].length == 2anddependencies[j].length == 21 <= taskId <= 10^5, and all task IDs are different.1 <= duration <= 10000 <= dependencies.length <= 3000- Every dependency
[before, after]uses two different task IDs fromtasks, and no pair appears twice.
More Rippling Phone Screen questions
- Filter, Sort, and Deduplicate Scheduled TasksPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Stateful Log Transform and SearchPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dependency-Aware Task SchedulerPHONE SCREEN · Seen Nov 2026
- Delivery Cost Tracker with Effective-Dated RatesPHONE SCREEN · Seen Nov 2026
- Camel CardsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best and Worst Camel Card CompletionsPHONE SCREEN · Seen Nov 2026
- Corporate Card Expense RulesOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- In-Memory Priority Task SchedulerPHONE SCREEN · Seen Oct 2026
- Limit an Organization Tree's HeightPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Median Across N Sorted ArraysPHONE SCREEN · Seen Oct 2026
Similar questions at other companies
- Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
- Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Subsequences Into a Consistent Total OrderGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Lexicographic Dependency OrderIllumio · PHONE SCREENIllumio interview questions
- Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Order Sources by Their DependenciesRetool · PHONE SCREENRetool interview questions
- Dependency-Aware Agent Task SchedulerOpenAI · PHONE SCREENOpenAI interview questions
- Lexicographically Smallest Dependency OrderOkta · PHONE SCREENOkta interview questions
- Course Completion OrderIndeed · PHONE SCREENIndeed interview questions
Interview reports that mention this question
- Rippling No-Level Onsite Loops: 24 Experiences (Part 5 of 6)
- Rippling SWE Interviews, No Level: 156 Experiences (Part 1 of 6)
- Rippling SDE-1 and SDE-2 Onsites: 14 Experiences (Part 9 of 12)
- Rippling Intern Phone Screens: 28 Experiences (Part 3 of 5)
- Rippling SWE Intern Interviews: 101 Experiences (Part 1 of 5)
- Rippling Full-Time SWE Interviews: 224 Experiences (Part 1 of 12)