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
Coding & Algorithms
Software Engineer
Uber
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
DFS
cycle detection
three-color marking
directed graph
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported