Report the Exact Cycle Among Circular NuGet Package References
Last updated: November 29, 2026
Quick Overview
Given a directed graph of NuGet package references, return one dependency cycle as a list of package names in order (first package repeated at the end), or an empty list if the graph is acyclic.
Microsoft
November 29, 20260
0
0 solved
Given a directed graph of NuGet package references, return one dependency cycle as a list of package names in order (first package repeated at the end), or an empty list if the graph is acyclic.
A DFS cycle-detection problem in the style of Microsoft screens, framed around dotnet restore failing on circular references. Detecting that a cycle exists is easy; the interviewer wants the actual cycle for a useful error message, which tests three-color DFS and parent tracking.
What the Interviewer Expects
- Use white, gray, black coloring for directed cycle detection
- Recognize a back edge to a gray node as a cycle
- Reconstruct the cycle from the current DFS stack
- Use an iterative DFS or note recursion limits
- Handle disconnected graphs by starting DFS from every node
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 list every elementary cycle?
- How would you find the smallest set of edges to remove to break all cycles?
- How would you report cycles in a build graph with millions of nodes?
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: dictionary refs mapping package name to the names it references. Packages that only appear as targets may be absent as keys. Output: a cycle like ["A", "B", "C", "A"] or []. Any cycle is ...
High-Level Design
Three-color DFS. White means unvisited, gray means on the current recursion path, black means fully explored. When the DFS from node u finds a neighbor v that is gray, the edge u -> v closes a cycle...