Schedule Data Pipeline Stages Into Parallel Execution Waves
Last updated: November 29, 2026
Quick Overview
Given the stages of a data preparation pipeline and precedence constraints between them, group stages into the fewest sequential waves where every stage's prerequisites finish in earlier waves, returning None if the dependencies contain a cycle.
OpenAI
November 29, 20260
0
0 solved
Given the stages of a data preparation pipeline and precedence constraints between them, group stages into the fewest sequential waves where every stage's prerequisites finish in earlier waves, returning None if the dependencies contain a cycle.
Preparing pretraining data at OpenAI involves many dependent stages (deduplication, filtering, tokenization, packing) that run on shared clusters, and running independent stages together cuts wall-clock time. This is level-order topological sorting; interviewers check Kahn's algorithm, cycle detection, and why the number of waves equals the longest dependency chain.
What the Interviewer Expects
- Build in-degree counts and adjacency lists
- Process stages level by level so each wave is a frontier
- Detect cycles by comparing processed count to total
- Explain why the wave count is the length of the longest path
- Produce deterministic output by sorting within a wave
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Each stage has a duration: what is the minimum total time with unlimited workers?
- Only k workers are available: how would you schedule, and is it still optimal?
- If there is a cycle, return one cycle to show the user.
- A stage fails: which downstream stages must be rerun?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
stagesanddepswhere(a, b)meansamust finish beforeb. - Output: list of waves; each wave is a sorted list of stages that can run in parallel.
- Every stage appears exactly once...
High-Level Design
Compute in-degrees. The first wave is every stage with in-degree zero. Processing a wave decrements the in-degree of each successor; any successor reaching zero joins the next wave. This is BFS where ...