← Questions

Weighted data batcher with deterministic resume

0
AnthropicMicrosoftCodingLast asked May 2026

A coding interview question asked in Anthropic's coding round and at Microsoft, last asked May 2026. It tests data loading, sampling and checkpointing.

Build a sampler that draws weighted batches from a dataset registry and can resume deterministically from a saved offset, including the edge case where the batch size does not divide the data evenly.

class WeightedBatcher:
    def __init__(self, datasets, weights, batch_size, seed=0, max_samples=None, drop_last=False, state=None): ...

    def next_batch(self):
        """A list of (dataset name, item), or None when the run is over."""

    def state(self):
        """Something JSON-friendly that resumes the exact same stream."""

Clarifying questions

  • Are weights sampling probabilities per item (with replacement), or quotas so each batch is split across datasets by weight?
  • When a dataset runs out, is it reshuffled and reused, or dropped and the remaining weights renormalized?
  • With drop_last, is a short final batch dropped only at max_samples, or whenever an epoch ends mid-batch?
  • What exactly must match after resume: the same items in the same order as a run that never stopped?
  • Can datasets be large lazy sequences, so the state can't hold a copy of them?

What a strong answer covers

  • All randomness from one seeded generator per stream (for example derived from seed plus an epoch counter), so the stream is a pure function of seed and position.
  • State as small numbers: per-dataset cursor and epoch, samples emitted, and the generator state (or enough to regenerate it), not the data itself.
  • Per-dataset shuffles regenerated from (seed, dataset, epoch) on resume instead of stored.
  • The last partial batch: either returned short or dropped by drop_last, and max_samples ending the run exactly.
  • Tests that compare an uninterrupted run with one stopped and resumed at every batch boundary, uneven batch sizes, a zero weight, and a dataset with one item.

Follow-ups

  • Resume onto a different number of data-parallel workers without repeating or skipping items.
  • Change the weights mid-run (a curriculum) and still resume deterministically.
  • Stream datasets that don't fit in memory and can't be shuffled in full.
  • How would you verify in production that no sample was seen twice?

Where it's asked

  • Anthropic · Coding · Last asked May 202655 min · Live coding on a realistic, multi-part problem, a different one from the screen · No AI
  • Microsoft · Coding · Last asked Mar 202660 min · Ten to fifteen minutes of behavioral questions, then coding in HackerRank where you write a main and make the tests pass; usually three rounds · No AI unless the interviewer invites it; some 2026 loops add a round where you bring your own AI agent

What it tests

data loading · sampling · checkpointing

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding