Fewest Parallel Rounds to Roll Out Services With Dependencies
Last updated: November 29, 2026
Quick Overview
There are n services and dependency pairs [a, b] meaning a must be rolled out before b. In each round you may roll out any number of services whose dependencies are all done. Return the minimum number of rounds, or -1 if a cycle makes rollout impossible.
Meta
November 29, 20260
0
0 solved
There are n services and dependency pairs [a, b] meaning a must be rolled out before b. In each round you may roll out any number of services whose dependencies are all done. Return the minimum number of rounds, or -1 if a cycle makes rollout impossible.
A Meta onsite question set in the world of staged infrastructure rollouts, where independent services ship in parallel. The interviewer checks that you see the answer as the number of Kahn's algorithm layers (the longest chain in the DAG) and that you detect cycles with the same pass.
What the Interviewer Expects
- Run Kahn's algorithm level by level, counting layers
- Explain that the layer count equals the longest path in vertices
- Detect a cycle when fewer than n services are processed
- Keep time at O(n + e)
- Contrast with a plain topological sort that loses the layering
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
- What if each round can roll out at most k services?
- How would you return which services go in each round?
- How do you compute the answer if each service takes a different amount of time?
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:
nservices labeled0..n-1, list of[a, b]edges. - Unlimited parallelism within a round.
- Output: minimum rounds, or
-1if impossible....
High-Level Design
A service can go out in round r only after everything it depends on is out, so its earliest round is one more than the latest round among its prerequisites. Rolling out greedily as early as possible...