Implement Global Holdout Assignment Over an A/B Test
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: easy
Interview Round: Other
Implement `assign_with_holdout(user_id, holdout_salt, exp_salt, holdout_pct, control_pct)`, which layers a global holdout on top of an A/B test. Users first pass a holdout hash gate, and only non-holdout users are bucketed into a variant. Each gate uses its own salt so holdout membership is independent of variant.
Requirements:
- Holdout gate: `h = int(hashlib.md5(f"{holdout_salt}:{user_id}".encode("utf-8")).hexdigest(), 16) % 100`. If `h < holdout_pct`, return `"holdout"` immediately.
- Otherwise: `b = int(hashlib.md5(f"{exp_salt}:{user_id}".encode("utf-8")).hexdigest(), 16) % 100`. Return `"control"` if `b < control_pct`, else `"treatment"`.
- Both comparisons use strict less-than.
- Return exactly one of `"holdout"`, `"control"`, or `"treatment"`.
```hint Match the recipe exactly
Every detail of the hash input changes the bucket: the salt, the colon separator, the UTF-8 encoding, and reading the full hex digest as a base-16 integer.
```
### What a Strong Answer Covers
- The exact hash recipe for each gate, strict less-than at both comparisons, and an early return for holdout users.
- Why each gate needs its own salt, and what happens to the split when one salt drives both.
- The share of all users that lands in each group, given that `control_pct` applies only to users outside the holdout.
- Determinism: the same inputs give the same group in every process and on every machine.
### Follow-up Questions
- Why must `holdout_salt` and `exp_salt` be independent?
- How would you resize the holdout later without reshuffling variant assignments?
- How would you check from logged assignments that the realized split matches the configured percentages?
Overview: Implement deterministic user assignment that layers a global holdout on top of an A/B test, using a separate salted md5 hash for each gate. It tests hash-based bucketing, why each layer needs its own salt, and how resizing the holdout affects existing variant assignments.