SDE Path

Feature Flag Service

Easy

Feature Flag Service

Design a feature-flag store that supports full on/off overrides and deterministic percentage rollouts by user bucket.

Requirements

  • Each flag holds at most one configuration at a time, and the latest set or rollout replaces whatever was there before. A flag that was never configured is disabled.
  • set(flag, on) installs a full override: on = 1 → always enabled, on = 0 → always disabled, regardless of bucket. It clears any prior rollout.
  • rollout(flag, pct) installs a percentage rollout for pct in 0..100, and clears any prior full override.
  • isEnabled(flag, userBucket) with userBucket in 0..99:
    • if the flag has a full override → return that on/off value (override always wins);
    • else if the flag has a rollout pct → return userBucket < pct (so rollout 0 is off for everyone, rollout 100 is on for every bucket 0..99, and userBucket == pct is off);
    • else (unknown flag) → return false.
  • Fully deterministic: the same bucket always gets the same answer for a given config — no hashing, no randomness.

API to implement

Implement the class FeatureFlags. The I/O driver is already written in the starter code — it parses the command script below and calls your methods. You only implement the class.

| Command | Returns | Behavior | |---|---|---| | set <flag> <on> | — | Set a full override for flag: on = 1 forces it fully enabled, on = 0 fully disabled. This replaces any earlier rollout or override on the same flag. | | rollout <flag> <pct> | — | Enable flag for the first pct percent of buckets (pct in 0..100). Clears any full on/off override on the flag; replaces any earlier config. | | isEnabled <flag> <userBucket> | boolean | Return whether flag is on for userBucket (0..99). A full override wins outright; otherwise a rollout of pct is on iff userBucket < pct; an unconfigured flag is false. |

Input format

The first line contains Q, the number of operations. Each of the next Q lines is one command as listed above. String arguments contain no spaces.

Output format

For each command with a non-void return, print its result on its own line, in order. The driver does this for you — your methods just return values.

This is a design problem: the hidden tests exercise edge cases and interaction sequences, not performance tricks. Model the state cleanly and the tests will pass.

Sample cases

Example 1
Input
5
isEnabled alpha 0
rollout alpha 50
isEnabled alpha 49
isEnabled alpha 50
isEnabled alpha 99
Expected output
false
true
false
false
Example 2
Input
6
rollout beta 30
isEnabled beta 10
set beta 1
isEnabled beta 99
set beta 0
isEnabled beta 0
Expected output
true
true
false