FastPrepPriority-Aware Dependent Task Order
Problems/Priority-Aware Dependent Task Order

Priority-Aware Dependent Task Order

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes task durations, tasks that become ready only after their dependencies, picking by priority, and a follow-up where tasks arrive online. It does not give the processor model, how to break ties, what to do with cycles, or the shape of the result. Our version is about 84% the same as the reported question.

You are given n = durations.length tasks numbered from 0 to n - 1. Task i takes durations[i] time units and has priority priorities[i]. Each row [before, after] in dependencies means task after may run only after task before finishes.

One worker executes exactly one task at a time. Whenever the worker becomes free, choose among all ready unfinished tasks using these rules:

  1. Choose the task with the greater numeric priority.
  2. If priorities tie, choose the smaller task ID.

Start at time 0 and never leave the worker idle while a task is ready. Return the complete schedule as rows [taskId, startTime, endTime] in execution order. The final row's end time is the minimum time needed by this one-worker policy to finish every task.

Interview extension

If tasks arrive over time, keep the same indegree counts and ready-task heap. Add each arriving task and its dependency edges to the maintained graph, and insert it into the heap as soon as every known prerequisite has finished.

Function

schedulePriorityTasks(durations: int[], priorities: int[], dependencies: int[][]) → int[][]

Examples

Example 1

durations = [3,2,4,1,2]priorities = [2,5,1,5,3]dependencies = [[0,2],[1,2],[2,4]]return = [[1,0,2],[3,2,3],[0,3,6],[2,6,10],[4,10,12]]

Tasks 1 and 3 initially tie for the greatest priority, so task 1 wins by smaller ID. Task 2 becomes ready only after both tasks 0 and 1 finish, and task 4 becomes ready after task 2.

Example 2

durations = [2,1,3]priorities = [1,9,5]dependencies = [[0,1],[1,2]]return = [[0,0,2],[1,2,3],[2,3,6]]

The dependency chain determines the only valid order even though task 1 has the greatest priority.

Example 3

durations = [1,1,1]priorities = [2,2,3]dependencies = []return = [[2,0,1],[0,1,2],[1,2,3]]

All tasks are ready at time 0. Task 2 has the greatest priority, then tasks 0 and 1 follow in ID order.

Constraints

  • 1 <= n == durations.length == priorities.length <= 100000.
  • 1 <= durations[i] <= 1000.
  • -10^9 <= priorities[i] <= 10^9.
  • 0 <= dependencies.length <= 200000.
  • Every dependency is a unique pair of distinct task IDs in [0,n).
  • The dependency graph is acyclic.

More Google Onsite Interview questions

  • 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
  • Route Pattern MatcherPHONE SCREEN · ONSITE 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

  • Dependency-Aware Agent Task SchedulerOpenAI · PHONE SCREENOpenAI interview questions
  • Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
  • Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
  • Lexicographically Smallest Course OrderLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • ETL Pipeline SchedulerUnity · ONSITE INTERVIEW
  • Microservice Deployment OrderGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Course Schedule IIWalmart · ONSITE INTERVIEWWalmart interview questions
  • Task Order With PrerequisitesDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Course Schedule IIBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int[][] schedulePriorityTasks(int[] durations, int[] priorities, int[][] dependencies) {
        // Write your code here.
    }
}
Checking account…