Find a Circular Prerequisite Chain Among Feature Flags
Last updated: November 29, 2026
Quick Overview
Feature flags can require other flags to be enabled first; given the prerequisite map, return one cycle as a list of flag names (starting and ending with the same flag), or an empty list if the configuration is acyclic.
Uber
November 29, 20260
0
0 solved
Feature flags can require other flags to be enabled first; given the prerequisite map, return one cycle as a list of flag names (starting and ending with the same flag), or an empty list if the configuration is acyclic.
Uber's configuration and experimentation platform lets teams chain flags, and a circular prerequisite would make a feature impossible to enable. The phone screen checks three-color DFS and, more usefully, reconstructing the actual cycle so the error message is actionable.
What the Interviewer Expects
- Use DFS with white, gray, black states
- Detect a back edge to a gray node
- Reconstruct the cycle from the recursion path
- Handle flags that only appear as prerequisites
- Mention recursion depth limits for large configs
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 all cycles, or the strongly connected components?
- How would you validate a single new edge quickly before saving it?
- Write the iterative version to avoid recursion limits
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: dict
requires[flag] = [prereq, ...]. - Output: list like
['a', 'b', 'c', 'a']describing a cycle, or[]. - Any one cycle is acceptable....
High-Level Design
Run DFS from every unvisited flag. Mark a flag gray when entering and black when finished, and keep the current path on a stack. Reaching a gray flag means a back edge: the cycle is the path from that...