Reported June 2026
Scale AIheap priority queue

Task Processor: Dependencies and Deadlines

Reported by candidates from Scale AI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Scale AI OA. Under 2s to a working solution.
Founder's read

The Scale AI OA reported in June 2026 hands you a task processor and a trap. Task 1 has the earlier deadline, but it can't run until task 2 is done, and a greedy sort by deadline gets that wrong immediately. This is a topological sort with a min-heap on top. You track which tasks are eligible, always pull the smallest deadline, and break ties by lexicographic id. If the pattern slips away mid-assessment, StealthCoder runs invisibly on your desktop and gives you a working solution as a safety net.

The problem

You are building a task processor. Each task has a string id, an integer deadline, and a list of subtasks that must be consumed before the task itself can be consumed.
Given all tasks up front, repeatedly consume one eligible task until no tasks remain. A task is eligible when all of its subtasks have already been consumed. Among all eligible tasks, always consume the task with the smallest deadline. If multiple eligible tasks have the same deadline, consume the lexicographically smaller task id first.
Return the ids of the tasks in the order they are consumed.

Function
consumeTasks(taskIds: String[], deadlines: int[], subtasks: String[][]) → String[]

Examples
Example 1
taskIds = ["1", "2"]
deadlines = [2, 4]
subtasks = [["2"], []]
return = ["2", "1"]
Task 1 has the earlier deadline, but it depends on task 2, so task 2 must be consumed first.
Example 2
taskIds = ["a", "b", "c"]
deadlines = [5, 1, 3]
subtasks = [[], [], []]
return = ["b", "c", "a"]
With no dependencies, tasks are consumed by increasing deadline.

Constraints
taskIds.length == deadlines.length == subtasks.length
Task ids are unique non-empty strings.
Every id listed in subtasks appears in taskIds.
The dependency graph is a DAG.
Use a min-heap or priority queue for currently eligible tasks.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is Kahn's algorithm with a priority queue instead of a plain queue. Build an in-degree count for each task from its subtasks list, and a reverse map from each subtask to the tasks that depend on it. Push every task with in-degree zero into a min-heap keyed by (deadline, id). Pop one, append it to the result, then decrement in-degree for each dependent and push any that hit zero. The edge case that breaks the naive version is sorting everything by deadline up front, which ignores dependencies. A second pitfall is comparing ids as numbers instead of strings, so "10" must sort before "2". Also remember the subtasks list holds ids, not indexes, so map id to index first. Complexity is O(n log n + edges). If you blank on the reverse-edge direction, StealthCoder is the hedge during the live OA.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Task Processor: Dependencies and Deadlines 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Scale AI's OA.

Scale AI reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Task Processor: Dependencies and Deadlines FAQ

What's the core trick in the Scale AI task processor problem?+

Topological sort driven by a min-heap. Only tasks with zero unconsumed subtasks go into the heap, ordered by deadline and then id. Each pop unlocks its dependents. Sorting by deadline alone fails because a dependency can force a later-deadline task to run first.

How do I handle ties on deadline?+

Make the heap key a tuple of (deadline, id) and compare id as a string, not a number. That gives lexicographic order, so "10" comes before "2". In Java, use a comparator that checks deadline first, then calls compareTo on the ids.

How hard is this problem really?+

Medium. If you know Kahn's algorithm, it's about twenty lines. The difficulty is noticing that a plain queue isn't enough and that you need a heap. The prompt even hints at a priority queue, so the pattern is easier to spot than usual.

What data structures do I need to set up?+

A map from id to index, an in-degree array, and a reverse adjacency list from each subtask to the tasks that depend on it. Then a min-heap holding the currently eligible tasks. Build in-degree from the subtasks lists, seed the heap, and loop until it's empty.

How do I prepare for this in 48 hours?+

Write Kahn's algorithm from scratch twice, once with a queue and once with a heap. Then test your code on the two examples and a case with equal deadlines. Check that you build the reverse edges correctly, since that's where most bugs show up.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Scale AI.

OA at Scale AI?
Invisible during screen share
Get it