Compute the fraction of users assigned the same variant under two experiment salts
Role: Data Scientist
Category: Analytics & Experimentation
Difficulty: medium
Interview Round: Other
Implement `def salt_reuse_overlap(user_ids: list[str], salt_a: str, salt_b: str) -> float`. For each id, compute a 50/50 variant under both salts and return the fraction of ids assigned the same variant under both.
Requirements:
- Variant is `"control"` when `int(hashlib.md5(f"{salt}:{user_id}".encode("utf-8")).hexdigest(), 16) % 100 < 50`, else `"treatment"`.
- Return `matches / len(user_ids)` as a plain `float` in `[0.0, 1.0]`.
- Raise `ValueError` when `user_ids` is empty.
Example:
```python
salt_reuse_overlap(["u1", "u2", "u3"], "exp", "exp")
# -> 1.0 (same salt: every id matches)
salt_reuse_overlap(many_ids, "exp_a", "exp_b")
# -> ~0.5 (independent salts concentrate near 0.5)
```
```hint One rule, two calls
Write the bucketing rule once as a helper that takes a salt and an id, then call it twice per id.
```
```hint Before the loop
Check the empty-list case first, since the return value divides by the list length.
```
### Constraints & Assumptions
- The hashed string is exactly `f"{salt}:{user_id}"`: salt first, one colon, no spaces, encoded as UTF-8, with the full MD5 digest read as one integer.
- The denominator is the raw list length, so an id that appears twice counts twice.
### What a Strong Answer Covers
- An assignment helper that follows the pinned hash recipe exactly
- The empty-input guard and a plain `float` result
- Why identical salts give exactly 1.0 and independent salts give about 0.5
- What the overlap fraction says about correlation between two experiments, and why reused salts confound them
- Time and space complexity
### Follow-up Questions
- Why is the result exactly `1.0` when `salt_a == salt_b`?
- Why does the fraction concentrate near `0.5` for independent salts, and how close to 0.5 should it be for 10,000 ids?
- How would you check a set of live experiments for accidental salt reuse before launch?
Overview: Write a Python function that hashes user ids into 50/50 variants under two experiment salts and returns the fraction assigned the same variant under both. It tests deterministic hash bucketing, why reusing a salt across experiments confounds them, and what overlap to expect from independent salts.