← Questions
Anthropic OA: leveled in-memory record store
0
I was asked this
No reports yet. Sign in to say where you were asked it.
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)(Nonewhen missing),delete(key, field)(returns whether a live field was removed). -
Level 2:
scan(key)andscan_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 fortimestamp <= 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 beforetimestamp_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): ...
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.
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.
Sign in to submit your code; every attempt is kept here.
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


