Count Deployment Waves Needed to Roll Out Dependent Microservices
Last updated: November 29, 2026
Quick Overview
Given n microservices and pairs (a, b) meaning a must be deployed before b, a deployment wave can include any service whose prerequisites were deployed in earlier waves. Return the minimum number of waves, or -1 if the dependencies are circular.
Microsoft
November 29, 20260
0
0 solved
Given n microservices and pairs (a, b) meaning a must be deployed before b, a deployment wave can include any service whose prerequisites were deployed in earlier waves. Return the minimum number of waves, or -1 if the dependencies are circular.
An entry-level topological sort question for Microsoft phone screens, framed around staged Azure service rollouts. The interviewer checks a level-by-level Kahn's algorithm and cycle detection, and may ask how this relates to the longest path in the DAG.
What the Interviewer Expects
- Build in-degrees and an adjacency list
- Process the ready queue one level at a time
- Count levels as waves
- Detect cycles when some services never become ready
- Relate the wave count to the longest path in nodes
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 wave can contain at most W services?
- How would you output which services go in each wave?
- How do you handle a dependency that is added mid-rollout?
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: integer n and a list of dependency pairs. Output: smallest number of waves, where every service in a wave has all prerequisites in earlier waves. Zero services means zero waves....
High-Level Design
Kahn's algorithm by levels. Compute each service's in-degree, then put every in-degree-zero service into the first wave. To form the next wave, go through the current wave and decrement the in-degree ...