Reported July 2026
Anthropicdesign

In-Memory Database Historical Lookup

Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Anthropic OA. Under 2s to a working solution.
Founder's read

The edge case that kills most solutions on this Anthropic OA, reported in July 2026, is the one where an older value tries to come back from the dead. You're building an in-memory database with historical lookback, and the spec says a newer write replaces the old value from its own timestamp onward, even after the newer one expires. It's a design problem dressed up as a key-value store. Per-field version history, plus a clean rule for what's visible at time T. If you blank on the visibility logic during the live assessment, StealthCoder runs invisibly as a safety net while you work through it.

The problem

Implement a field-based in-memory database that can answer historical lookback queries. Every operation argument is encoded as a string, and operation timestamps are strictly increasing.
Operations
["SET_AT", key, field, value, timestamp]: set or overwrite the field beginning at timestamp. The value does not expire. Return an empty string.
["SET_AT_WITH_TTL", key, field, value, timestamp, ttl]: set or overwrite the field. It is visible during the half-open interval [timestamp, timestamp + ttl). Return an empty string.
["DELETE_AT", key, field, timestamp]: delete the value visible at timestamp. Return true if a visible field was deleted, or false otherwise.
["GET_WHEN", timestamp, key, field, at_timestamp]: return the value that was visible at at_timestamp. Return null if the record or field did not exist then. It is guaranteed that at_timestamp <= timestamp.
When at_timestamp is 0, return the value currently visible at the operation's own timestamp.
Keep expired and deleted versions in history so earlier lookback queries remain answerable. A newer write replaces the older value from its own timestamp onward; an older value does not reappear when the newer value expires.

Function
inMemoryDatabaseHistoricalLookup(operations: String[][]) → String[]

Examples
Example 1
operations = [["SET_AT","A","score","10","1"],["SET_AT_WITH_TTL","A","score","20","5","5"],["GET_WHEN","6","A","score","2"],["GET_WHEN","7","A","score","5"],["GET_WHEN","10","A","score","9"],["GET_WHEN","11","A","score","10"],["SET_AT","A","score","30","12"],["GET_WHEN","13","A","score","0"],["DELETE_AT","A","score","14"],["GET_WHEN","15","A","score","13"],["GET_WHEN","16","A","score","14"]]
return = ["","","10","20","20","null","","30","true","30","null"]
The value 20 is visible on [5,10), so the lookback at 9 finds it while the lookback at 10 returns null. Deleting at 14 does not erase the value 30 from earlier history.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Store a list of versions per (key, field). Each version holds a start timestamp, an optional end (timestamp + ttl, half-open), and the value. Since timestamps strictly increase, the list stays sorted, so a binary search on start time finds the latest version with start <= at_timestamp. Then check that at_timestamp is below its end. If it's not, return null. Don't fall back to an earlier version. That's the trap. A newer write shadows everything older from its start time. Deletes are the other trap. DELETE_AT should cap the visible version's end at the delete timestamp rather than erase history, so lookbacks before 14 still return 30. Also remember at_timestamp of 0 means use the operation's own timestamp. Parse everything from strings, and return the literal string null, not a null value. StealthCoder is your hedge if the version-shadowing logic slips under time pressure.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill In-Memory Database Historical Lookup cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Anthropic's OA.

Anthropic reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

In-Memory Database Historical Lookup FAQ

What's the trick in the Anthropic in-memory database historical lookup problem?+

Keep a sorted version list per key and field. For a lookback, find the latest version that started at or before at_timestamp, then check its end. If it's expired or deleted, return null. Never fall through to an older version, because newer writes shadow older ones permanently.

How do I handle DELETE_AT without losing history?+

Don't remove anything. Find the version visible at the delete timestamp. If one exists, set its end to the delete timestamp and return true. Otherwise return false. Earlier lookbacks still see the value because their at_timestamp falls before the new end.

What does at_timestamp of 0 mean in GET_WHEN?+

It means use the operation's own timestamp as the lookup time. Normalize it at the top of the handler: if at_timestamp is 0, set it to the timestamp argument. Forgetting this is an easy way to fail hidden tests even when the sample passes.

Why is the TTL interval half-open and why does it matter?+

A value with timestamp 5 and ttl 5 is visible on [5,10). At 9 you return it, at 10 you return null. Use start <= t < end. An off-by-one with <= on the end boundary breaks exactly the lookback at 10 in the example.

How should I prepare for this in 48 hours?+

Write the version-list structure from scratch once, with binary search or a linear scan from the end. Then trace Example 1 by hand. Watch the string conversions and the literal null output. Design-style OAs reward careful state modeling more than fancy algorithms.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Anthropic.

OA at Anthropic?
Invisible during screen share
Get it