Order Build Stages for Dependent Pricing Libraries
Last updated: November 29, 2026
Quick Overview
Given a list of internal libraries and the dependencies between them, produce the build stages such that every library is built after its dependencies and libraries in the same stage can build in parallel, or report a cycle.
Akuna Capital
November 29, 20260
0
0 solved
Given a list of internal libraries and the dependencies between them, produce the build stages such that every library is built after its dependencies and libraries in the same stage can build in parallel, or report a cycle.
Akuna Capital's pricing, risk and quoting code lives in large C++ and Python codebases with layered internal libraries. The interviewer wants Kahn's algorithm with level grouping, a clear cycle report, and some awareness of how this relates to build systems the team uses daily.
What the Interviewer Expects
- Model libraries as nodes with edges from dependency to dependent
- Use Kahn's algorithm and group by BFS level to get parallel stages
- Detect cycles by comparing processed count with node count
- Report which nodes are stuck when a cycle exists
- Keep output deterministic (sorted within a stage)
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
- How would you rebuild only what changed after one library is edited?
- How would you minimize total build time when libraries have different build durations?
- How would you print the actual cycle path, not just the stuck set?
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: library names and pairs (lib, needs) meaning lib depends on needs. Output: a list of stages, each a sorted list of libraries with all dependencies in earlier stages. If the graph has a cycle, r...
High-Level Design
Count in-degrees (number of unbuilt dependencies) per library and keep a reverse adjacency list from each library to its users. Stage 0 is every library with in-degree 0. Building a stage decrements i...