This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
Tag: Data Eng
CD0073 AI Idempotent Consumer
Square’s payments-infrastructure team owns the job runner that moves money into merchant balances, and its queue delivers every job message at least once. A worker timeout, a consumer rebalance, or a broker failover can hand the same
job_idto a worker twice, sometimes while the first copy is still being applied. In this 60-minute AI-enabled round you harden that runner in three phases. The rule never changes: a job may arrive any number of times, but it must move money exactly once.Phase 1 (unaided): the starter
JobHandlerbelow passes a smoke test that delivers a job twice in a row. In staging, the payout log still showspayout-7731creditingmerchant-42twice, about 40 ms apart, with both calls returning'applied'. The second delivery arrived while a slow ledger write for the first was still running. Repair the handler so it honors the contract in its comment, with no AI assistant. The one-shoton_credithook lets a test run code at the start ofcredit().Phase 2 (steer the AI): the single-process handler grows into
IdempotentConsumer. It runs as several replicas against a provided toy database,store.py, which offers transactions, a unique-key insert, an injected clock, and fault hooks. Pick the one prompt out of three whose contract is exact. Phase 3 (audit): the assistant’s draft passes the sequential demo. Find its three flaws, patch them in place, and prove the patch with a test.Phase 2 Target Contract: (1) A duplicate routed to another replica, or to a worker restarted after a deploy, is recognized. (2) A redelivery up to
REDELIVERY_HORIZON_S(24 h) after a job completes is recognized, while older dedup rows may be evicted to bound storage. (3) A worker that dies at any instant, including right after a commit, never causes a second credit on redelivery. (4) A duplicate that arrives while the first copy is in flight never credits. (5) A job whose credit fails before it commits stays retryable.Phase 1 Starter (payout_handler.py):
01 # payout_handler.py: Phase 1 starter (single process, no replicas yet) 02 03 04 class Ledger: 05 # Toy effect target: cents credited per merchant account. 06 def __init__(self): 07 self.balances = {} 08 self.on_credit = None # one-shot test hook, called at the start of credit() 09 10 def credit(self, account, cents): 11 if self.on_credit is not None: 12 hook, self.on_credit = self.on_credit, None 13 hook() 14 self.balances[account] = self.balances.get(account, 0) + cents 15 16 17 class JobHandler: 18 # Contract: a job_id moves money at most once, and a job whose 19 # credit raises must stay retryable when the queue redelivers it. 20 def __init__(self, ledger): 21 self.ledger = ledger 22 self.seen_ids = set() 23 24 def handle(self, msg): 25 job_id = msg['job_id'] 26 if job_id in self.seen_ids: 27 return 'duplicate' 28 self.ledger.credit(msg['account'], msg['cents']) 29 self.seen_ids.add(job_id) 30 return 'applied'
Figure 1: the round’s three phases and the delivery patterns the finished consumer must survive. Every pattern must credit merchant-42 exactly once, whichever replica or restarted worker receives the copy.
Progressive Hints (Free · Zero Spoilers)1Inspection Checklist (Where to Look)
(1) Claim Timing: For each line of
handle(), ask what a second delivery of the samejob_idwould observe if it arrived at exactly that moment.
(2) Failure Path: Trace what state is left behind whencredit()raises, and whether the queue’s redelivery can still succeed afterwards.
(3) Dedup Visibility: In Phase 3, list every process that could receive the job and check which copy of the dedup state each one actually reads.
(4) Retention Horizon: Compare how long a dedup record lives with how late the queue may redeliver.
(5) Durability Boundaries: Mark every commit in the draft and ask what survives if the process dies between two of them.2Visual Review Map (Figure 2)

Figure 2: One job’s path through a consumer. Each uniform ? marks a question you should settle before patching; the answers are yours to work out.
3Interviewer Nudge & Line Focus
Walk each phase and answer the Socratic check before editing:
Phase 1 (Claim-Finish Window): Between line 26 and line 29 the job is neither recorded nor finished. If theon_credithook delivers the same message again at that moment, what does line 26 report? Once a second look-up can see the job, what must the handler do so that a credit which raises does not look finished forever?Phase 2 (Spotting Flawed Prompts): All three prompts are the same length and sound rigorous. For each one, ask three questions: where does the dedup state live, how long must a dedup row survive relative toREDELIVERY_HORIZON_S, and which commit does the dedup row ride in? A prompt that leaves any one of them open lets the assistant pick the convenient answer.Phase 3 (Auditing the Consumer Draft): Run four thought experiments against the draft: a second replica constructed before the first delivery finishes, a worker that dies right after a commit and restarts, a fresh worker at hour 24 that runsevict_expired()first, and a duplicate delivered mid-commit on the same replica. Which of them end with 1,000 cents instead of 500?Answer
Login to view more contentCD0071 Backfill Double-Count Triage
This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
CD0069 Cache Stampede Triage
This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
CD0067 Debug Streaming Top-K
This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.
CD0063 Merge Accounts Union-Find
ByteDance’s account-integrity team works on a deceptively simple question: which user records belong to the same human? This coding screen (reported by candidates who interviewed with the team) distills it into a classic merge task. You receive
accounts, a list where each entry is[name, email_1, email_2, ...]. Two accounts belong to the same person if they share at least one email address, either directly or through a chain of other accounts. Return one row per person: the name followed by that person’s unique emails in sorted order.The solution must be union-find over email ownership in pure Python, with no imports beyond
typing. The interviewer probes three input shapes. The first is a chain, where account A shares an email with B and B shares one with C, but A and C share nothing directly. The second is two people with the same display name who must not be merged. The third is an email repeated inside one account. You also have to argue why path compression plus union by rank makes each operation near-constant amortized, and the code must handle a-account chain comfortably.
Fill the 4 blanks in the skeleton below. Then trace the
parentandrankarrays aloud on a small chain, and give the total running time in terms ofaccounts and
email occurrences.
Skeleton Code (Fill Blanks 1-4):
01 from typing import Dict, List 02 03 04 class DisjointSet: 05 """Union-find over account indices 0 .. n-1.""" 06 07 def __init__(self, n: int): 08 self.parent = list(range(n)) # each account starts as its own root 09 self.rank = [0] * n # upper bound on each root's tree height 10 11 def find(self, x: int) -> int: 12 # TODO (Blank 2): return the root of x; afterwards every node 13 # visited on the way must point directly at it 14 ... 15 16 def union(self, a: int, b: int) -> bool: 17 # TODO (Blank 3): link the roots of a and b by rank; return True 18 # on a merge, False if already in one set 19 ... 20 21 22 def merge_accounts(accounts: List[List[str]]) -> List[List[str]]: 23 """Merge accounts that share at least one email address. 24 25 accounts[i] = [name, email_1, email_2, ...]. Two accounts belong to 26 the same person iff a chain of shared emails connects them; an equal 27 name alone never justifies a merge. Returns one row per person: 28 [name] + that person's unique emails in sorted order. 29 """ 30 dsu = DisjointSet(len(accounts)) 31 email_owner: Dict[str, int] = {} # email -> first account index that listed it 32 33 for account_id, account in enumerate(accounts): 34 for email in account[1:]: 35 # TODO (Blank 1): register the first owner of each email; 36 # connect accounts only through a shared email 37 ... 38 39 # TODO (Blank 4): group every email under its account's root, then 40 # emit [name] + sorted unique emails per group 41 merged = ... 42 return merged
Figure 1: The input and output contract plus the four input shapes the hidden checks probe. The question-marked box is the whole exercise.
Progressive Hints (Free · Zero Spoilers)1Inspection Checklist (Where to Look)
(1) Ownership Key: Blank 1’s dictionary is the only place where accounts get linked. Decide what its key is, when an entry is created, and when an existing entry is reused.
(2) Root Contract:find(x)returns an index whose parent is itself. Decide what state the nodes you walked through should be left in.
(3) Link Direction:unionreceives two account indices that may sit deep inside their trees. Decide which nodes get rewired and which root survives.
(4) Grouping Key: Blank 4 needs a key that is identical for every account of one person at the moment you group, and each email must appear only once per row.2Visual Review Map (Figure 2)
![Visual review map: accounts of type List[List[str]] flow into Blank 1, marked with a question mark and typed as an email_owner Dict[str, int], then into a DisjointSet holding parent and rank integer lists, then into Blank 4, marked with a question mark and typed as merged rows List[List[str]]; Blank 2 typed find(x) returning int and Blank 3 typed union(a, b) returning bool both plug into the DisjointSet, each marked with a question mark](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjUyIiBoZWlnaHQ9IjUyOCIgdmlld0JveD0iMCAwIDEyNTIgNTI4Ij48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBzdHlsZT0iZmlsbDojY2ZkNGRiO2ZpbGwtb3BhY2l0eTogMC4xOyIvPjwvc3ZnPg==)
Figure 2: Each blank shows only its target type and its place in the data flow. The question mark is the step you write.
3Interviewer Nudge & Line Focus
Answer each Socratic check before you type the blank:
Blank 1 (Email Ownership Map): When an email shows up for the second time, which two account indices are now proven to be the same person? If you keyed the dictionary on the display name instead, what would happen to two unrelated people both called Ana?Blank 2 (Path-Compressed find): Iffind(5)walks the path 5, 4, 3, 2, 1, 0, how many hops should a secondfind(5)cost, and what does that imply about the five nodes you just walked? With Python’s default recursion limit of 1000, is a recursive walk safe on a 100,000-node path?Blank 3 (Union by Rank): You merge a rank-2 tree with a rank-1 tree. Which root becomes the child, and does any rank change? What shouldunionreturn the second time it sees two accounts that are already connected?Blank 4 (Group and Emit): After the last union, isparent[owner]guaranteed to equal the root ofowner? How many times can one email appear in a group if you iterate a structure whose keys are already unique, rather than the raw account lists?Answer
Login to view more contentCD0052 AI DAG Task Scheduler
This is an IntvML Pro interview question. Upgrade to Pro to unlock the full prompt, diagrams, and solution.



![Visual review map: accounts of type List[List[str]] flow into Blank 1, marked with a question mark and typed as an email_owner Dict[str, int], then into a DisjointSet holding parent and rank integer lists, then into Blank 4, marked with a question mark and typed as merged rows List[List[str]]; Blank 2 typed find(x) returning int and Blank 3 typed union(a, b) returning bool both plug into the DisjointSet, each marked with a question mark](https://intvml.com/wp-content/uploads/2026/11/CD0063-merge-accounts-union-find-review-map.jpg)