Anthropic OA: leveled in-memory record store

0
Sign in

A timed, multi-level exercise building an in-memory store of records with fields: create and read first, then scans and filters, then timestamps with expiry, then backup and restore to an earlier point. Each level builds on the previous one, and earlier tests keep running.

  • Level 1: set(key, field, value), get(key, field) (None when missing), delete(key, field) (returns whether a live field was removed).
  • Level 2: scan(key) and scan_by_prefix(key, prefix) return ["field(value)", ...] sorted by field.
  • Level 3: timed versions of every call (set_at, set_at_with_ttl, get_at, delete_at, scan_at, scan_by_prefix_at). A field with a TTL is alive for timestamp <= t < timestamp + ttl. Timestamps only grow.
  • Level 4: backup(timestamp) saves the live state and returns the number of records with a live field. restore(timestamp, timestamp_to_restore) rolls back to the latest backup at or before timestamp_to_restore; each field keeps the TTL it had left at backup time, counted from the restore.
class RecordStore:
    def set(self, key, field, value): ...
    def get(self, key, field): ...
    def delete(self, key, field): ...

    def scan(self, key): ...
    def scan_by_prefix(self, key, prefix): ...

    def set_at(self, key, field, value, timestamp): ...
    def set_at_with_ttl(self, key, field, value, timestamp, ttl): ...
    def get_at(self, key, field, timestamp): ...
    def delete_at(self, key, field, timestamp): ...
    def scan_at(self, key, timestamp): ...
    def scan_by_prefix_at(self, key, prefix, timestamp): ...

    def backup(self, timestamp): ...
    def restore(self, timestamp, timestamp_to_restore): ...
AnthropicMicrosoft AIAirbnbMetaxAIOnline assessmentMediumLast asked Sep 2026

Sign in to see the worked answer

The full answer, chapter by chapter, with what interviewers expect at each level. Free with an account: one full answer per company.