Problem, as an interviewer would state it:
"Implement isInBucket(userId, flagName, percentage) — deterministically decide whether a given user is in the rollout bucket for a feature flag, WITHOUT storing any per-user assignment state, such that roughly the configured percentage of ALL users end up in the bucket."
Examples:
isInBucket("user-42", "new-checkout", 30); // deterministic true/false, ~30% of users get true
Clarifying questions expected:
- Must the SAME user always get the SAME result for the SAME flag, across every real call, without storing anything?
- Should the SAME user potentially get a DIFFERENT bucketing decision for a DIFFERENT flag (independent assignment per flag)?
- Does the actual measured distribution need to closely match the configured percentage across a large, real population?
Code / implementation expected: Yes — real, direct proof of both determinism (repeated calls for the same user+flag) and distribution accuracy (measured across a large, real simulated user population).