Reported June 2026
Netflixgraph

Topological Sort for Ads Tasks

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

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

The whole Netflix problem hinges on one structure: a min-heap sitting on top of Kahn's algorithm. This one was reported in June 2026, and it's a topological sort with a deterministic tiebreak. Tasks, prerequisite edges, smallest available id goes first, empty array if there's a cycle. If you've seen course scheduling, you've seen 80% of it. The tiebreak is the twist that trips people who reach for a plain queue. If your mind goes blank mid-assessment, StealthCoder runs invisibly as a desktop overlay and can hand you the solution live. Better to walk in already knowing the shape.

The problem

You are given numTasks tasks labeled from 0 to numTasks - 1 and a list of prerequisite edges. Each edge [before, after] means task before must be completed before task after.
Return one valid order to complete all tasks. If more than one task is available at the same time, choose the smaller task id first so the result is deterministic. If it is impossible to complete all tasks because the dependency graph contains a cycle, return an empty array.

Function
findTaskOrder(numTasks: int, edges: int[][]) → int[]

Examples
Example 1
numTasks = 4
edges = [[0, 1], [0, 2], [1, 3], [2, 3]]
return = [0, 1, 2, 3]
Task 0 unlocks tasks 1 and 2. The smaller available id is chosen first.
Example 2
numTasks = 2
edges = [[0, 1], [1, 0]]
return = []
The two tasks depend on each other, so no valid topological order exists.

Constraints
0 <= before, after < numTasks
Use topological sorting with cycle detection.
When multiple tasks have in-degree zero, choose the smallest task id first.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build an adjacency list and an in-degree array from the edges. Push every task with in-degree zero into a min-heap. Pop the smallest id, append it to the result, then decrement the in-degree of each neighbor. Any neighbor that hits zero goes into the heap. When the heap empties, check the result length. If it equals numTasks, return it. Otherwise there's a cycle, so return an empty array. The common pitfall is using a regular FIFO queue. That gives a valid order but not the smallest-id-first one, so the expected output won't match. Another miss is forgetting the cycle check, or building the edge direction backwards. Edge [before, after] means before points to after. Complexity is O((V + E) log V). If you freeze on the heap detail during the live OA, StealthCoder is the hedge that gets you unstuck.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Topological Sort for Ads Tasks 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 passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as course schedule ii. If you have time before the OA, drill that.

⏵ The honest play

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

Netflix reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Topological Sort for Ads Tasks FAQ

What's the trick in the Netflix Topological Sort for Ads Tasks problem?+

Use Kahn's algorithm with a min-heap instead of a plain queue. The heap guarantees that when several tasks have in-degree zero, the smallest id is processed first. That's what makes the output deterministic and match the expected answer.

How do I detect the cycle?+

Count how many tasks you actually output. If the result has fewer than numTasks entries, some tasks never reached in-degree zero, which means they sit in a cycle. Return an empty array in that case. No separate DFS coloring is needed.

Can I use DFS instead of Kahn's algorithm?+

You can, but the smallest-id-first rule is awkward with DFS post-order. Kahn's with a heap handles the tiebreak naturally. Stick with it unless you have a strong reason, since the deterministic requirement is the whole point of this problem.

Is this pattern still asked in 2026?+

Topological sort stays a staple. This version was reported for Netflix in June 2026, so it's current. Expect variations like course schedule, build order, or task dependencies with a tiebreak rule added on top.

How do I prepare in 48 hours?+

Write Kahn's algorithm from scratch twice, once with a queue and once with a heap. Test the two examples plus a cycle and a graph with no edges. Watch edge direction and the final length check. That covers nearly every way this problem fails.

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

OA at Netflix?
Invisible during screen share
Get it