Identify Bugs in Python Script for User Assignment
Company: OpenAI
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Online Assessment
Overview: This question evaluates a candidate's ability to detect bugs and data-quality risks in a Python script, testing competencies in code review, reproducible randomization, idempotency, logging, duplicate-exposure safeguards, and safe experiment-assignment logic.
Constraints
- 1 <= len(users) <= 200000
- 0 <= treatment_rate <= 100
- 0 <= len(previously_triggered) <= 200000
- Each user_id is a non-empty ASCII string of length <= 64
- Deterministic bucket: bucket(seed, user) = (sum(ord(c) for c in seed + '|' + user)) % 100
- Return users in the order of first eligible appearance in the batch
- Trigger at most once per user in a single batch
Hints
- Use a deterministic bucket function; avoid Python's built-in hash due to runtime randomization.
- Use a set for previously_triggered and for users triggered in this batch to enforce idempotency and duplicate suppression.
- Compute a reusable base from the seed once to avoid repeated work.
- Process users in order and append only on the first eligible occurrence.