List Every On/Off Combination of Experiment Flags for a Test Matrix

Last updated: November 29, 2026

Quick Overview

Given a list of distinct experiment flag names, return every subset of flags that could be switched on together, including the empty set. Each subset should list flags in their original order.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of distinct experiment flag names, return every subset of flags that could be switched on together, including the empty set. Each subset should list flags in their original order.

A warm-up in Google phone screens, framed around building a test matrix for a launch that ships behind several experiment flags. The interviewer checks that you can write a clean include/exclude recursion and reason about the 2^n output size.

What the Interviewer Expects
  • Recognizes the output has exactly 2^n subsets
  • Writes a clean include/exclude or loop-based backtracking recursion
  • Copies the current path when recording a result instead of storing a shared reference
  • States time and space as O(n * 2^n) because of output size
  • Mentions an iterative or bitmask alternative
Key Topics to Cover
Backtracking
Power set
Recursion
Bitmask enumeration
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 generate only subsets of size at most k?
  • How would you stream subsets lazily with a generator so memory stays O(n)?
  • If some flags are mutually exclusive, how would you prune those subsets?
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: a list of distinct flag names, for example ["dark_mode", "new_ranker", "fast_cache"].
  • Output: all 2^n subsets, each preserving input order. The empty subset means "all flags off".
  • Order...
High-Level Design

Walk the flags left to right. At each index we make a binary decision: leave the flag off or turn it on. The recursion tree has depth n and 2^n leaves, one per subset.

A common, slightly tighter form...


Submit Your Answer
Markdown supported