Priority-Aware Dependent Task Order
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google's October 2026 report is a scheduling problem with a detail that matters: one worker, and the task with the greater priority goes first, ties broken by smaller ID. That's a topological sort with a priority queue bolted on. If you've got the OA in the next day or two, this is the shape to recognize. Tasks unlock through [before, after] dependencies, and the worker never sits idle while something is ready. It's simulation more than cleverness. StealthCoder is the safety net running invisibly if you blank on the heap ordering mid-assessment, but the logic below is short enough to hold in your head.
The problem
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: Choose the task with the greater numeric priority. 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. 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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is Kahn's algorithm with a heap instead of a plain queue. Build an indegree array and an adjacency list from dependencies. Push every task with indegree 0 into a min-heap keyed on (-priority, id). Keep a clock at 0. Pop the best ready task, set start to the clock, end to clock plus durations[i], append the row, then advance the clock to end. Decrement indegree for each child and push any that hit 0. Because one worker runs one task at a time, nothing becomes ready mid-task, so you only push after finishing. The pitfall is flipping the comparator wrong, since higher priority wins but smaller ID wins ties. Another is advancing the clock incorrectly. The heap is never empty while tasks remain, assuming no cycles. If the heap empties early, there's a cycle. StealthCoder is your hedge in the live OA if the comparator trips you up.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Priority-Aware Dependent Task Order cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Priority-Aware Dependent Task Order FAQ
What's the core trick for the Priority-Aware Dependent Task Order problem?+
Run Kahn's topological sort, but replace the queue with a heap ordered by higher priority first, then smaller task ID. Pop one ready task, run it to completion, update the clock, then release its dependents. That's the whole algorithm.
How do I order the heap in Python or Java?+
In Python, push tuples of (-priority, id,...) into heapq so the highest priority pops first and ties fall to the smaller ID. In Java, use a comparator that sorts priority descending, then ID ascending. Test it on the sample where tasks 1 and 3 tie.
Can a task become ready while another is running?+
Not under this policy. With one worker, dependents only unlock when a task finishes. So you add newly ready tasks right after completing the current one, then pop again. The worker never idles unless nothing is ready, which only happens with a cycle.
How hard is this really for a Google OA?+
Medium. Anyone who knows topological sort and heaps can finish it fast. The difficulty is wiring both together cleanly and getting the tie-break right. Time complexity is O((n + m) log n), where m is the number of dependencies.
How do I prepare in 48 hours?+
Write Kahn's algorithm from memory twice, then swap in a heap with a custom key. Trace the sample by hand, checking that task 2 waits for both 0 and 1. Then handle edge cases like no dependencies or a single task.