Return One Dependency Cycle Among Feature Flag Prerequisites
Last updated: November 29, 2026
Quick Overview
Feature flags can require other flags to be enabled first. Given flags and prerequisite edges [a, b] meaning a requires b, return one cycle as a list of flags in order (for example [x, y, z, x]) if any cycle exists, otherwise return an empty list.
Meta
November 29, 20260
0
0 solved
Feature flags can require other flags to be enabled first. Given flags and prerequisite edges [a, b] meaning a requires b, return one cycle as a list of flags in order (for example [x, y, z, x]) if any cycle exists, otherwise return an empty list.
A Meta onsite coding question in the style of internal config tooling, where a cyclic prerequisite makes a flag impossible to turn on. Detecting a cycle is the easy half; the interviewer is checking that you can recover the actual cycle path for an actionable error message, using three-color DFS with parent tracking.
What the Interviewer Expects
- Use white, gray, black coloring to detect a back edge
- Reconstruct the cycle from the DFS stack when a gray node is hit
- Write an iterative DFS or justify recursion depth
- Cover disconnected components by starting from every unvisited node
- Analyze O(V + E) time
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 report every elementary cycle, and why is that expensive?
- How would you find the shortest cycle through a given flag?
- If flags are added one at a time, how would you reject the edge that would create a cycle?
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: list of flag names and
edgesas[a, b](a requires b). - Output: one directed cycle written as
[v0, v1, ..., vk, v0]following edge direction, or[]. - Self-loops count as a cycle `[a...
High-Level Design
Kahn's algorithm tells you a cycle exists (some nodes never reach in-degree zero) but not which one. DFS coloring does both:
- White: unvisited. Gray: on the current DFS path. Black: full...