Dependency-Aware Task Scheduler
Updated
Problem statement
You are given a list of task ids, a list of dependencies, a priority for each task, and a flag for each task that says whether it is included. A dependency [before, after] means before must come before after.
Only tasks whose included value is true take part. Ignore any dependency that has a filtered-out task at either end. Then build the schedule one task at a time. At each step, look at the tasks whose prerequisites are all done. Pick the one with the highest priority. If two tasks have the same priority, pick the lexicographically smaller task identifier.
Return the schedule. If the included tasks have a dependency cycle, return an empty array.
Function
scheduleTasks(taskIds: String[], dependencies: String[][], priorities: int[], included: boolean[]) → String[]Examples
Example 1
taskIds = ["extract","clean","load","audit"]dependencies = [["extract","clean"],["clean","load"]]priorities = [2,5,4,9]included = [true,true,true,true]return = ["audit","extract","clean","load"]Task audit has no prerequisites and the highest priority, so it goes first. Then extract is the only task that is ready, followed by clean and then load, because each one waits for the one before it.
Example 2
taskIds = ["a","b","c"]dependencies = [["a","b"],["b","c"]]priorities = [1,10,5]included = [false,true,true]return = ["b","c"]Task a is filtered out, so the edge [a, b] is dropped with it. Now b has no prerequisites, so it goes first, and c follows. The answer is ["b","c"].
Example 3
taskIds = ["a","b"]dependencies = [["a","b"],["b","a"]]priorities = [1,2]included = [true,true]return = []Each task waits for the other, so neither can ever go first. The tasks form a cycle, and the answer is an empty array.
Constraints
1 <= taskIds.length == priorities.length == included.length <= 20000.- Task identifiers are unique nonempty ASCII strings.
-10^9 <= priorities[i] <= 10^9.0 <= dependencies.length <= 50000; every edge contains two known, different identifiers and edges are distinct.
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
- 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
- Delivery Cost TrackerPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Task Scheduler with Prerequisites and Execution PathsBrex · PHONE SCREEN
- 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