FastPrepPriority-Aware Dependent Task Order

Priority-Aware Dependent Task Order

Google logoGoogle● MediumINTERNONSITE INTERVIEW

Problem statement

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.

The problem statement continues
Pro

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.

FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
See Google hiring insights
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 2 more worked examples, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week