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
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
topological sort
BFS levels
DAG
cycle detection
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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 ...


Submit Your Answer
Markdown supported