Derive a Microservice Build Order and Report Any Dependency Cycle

Last updated: November 29, 2026

Quick Overview

Given a list of services and pairs `(service, depends_on)`, return an order in which every service is built after all of its dependencies; if that is impossible, return one concrete dependency cycle instead.

EPAM Systems
Coding & Algorithms
Software Engineer
EPAM Systems
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Medium

0

0

0 solved


Given a list of services and pairs `(service, depends_on)`, return an order in which every service is built after all of its dependencies; if that is impossible, return one concrete dependency cycle instead.

EPAM teams frequently inherit large multi-module or multi-repo estates during modernization work, and CI pipelines need a correct build order. Returning the actual cycle, not just false, is what makes the tool useful to a developer, and the interviewer checks you can extract it cleanly.

What the Interviewer Expects
  • Model as a directed graph with edges from dependency to dependent
  • Use DFS with three colors (or Kahn's algorithm) for topological order
  • Detect a back edge and reconstruct the cycle with parent pointers
  • Include services that appear only in dependency pairs
  • Avoid recursion depth limits for large graphs
Key Topics to Cover
topological sort
cycle detection
DFS coloring
build systems
directed graphs
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
  • How would you produce build waves so independent services build in parallel?
  • How would you use Kahn's algorithm instead, and how would you report a cycle there?
  • How would you rebuild only what changed after a commit touches one service?
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

Output (order, None) with every node, or (None, cycle) where cycle lists services in depends-on direction and repeats the start at the end, for example a -> b -> c -> a. Nodes may appear only ...

High-Level Design

Add an edge dep -> svc meaning dep must come first. Run iterative DFS with WHITE (unvisited), GRAY (on current path) and BLACK (finished) colors. When a node finishes, append it; reversing the finis...


Submit Your Answer
Markdown supported

Related Questions