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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

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
cycle detection
DFS coloring
path reconstruction
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 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 Problems
Sample Answer
Requirements
  • Input: list of flag names and edges as [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...

Submit Your Answer
Markdown supported