Segmented Durable Key-Value Store
Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that trips people on this OpenAI question, reported July 2026, is the record encoding: keyLength:key then valueLength:value, and an empty value still costs bytes. It's a pure simulation problem. You keep a map, an append-only log, and a list of segment sizes, then run commands in order. Nothing fancy, but one off-by-one in the byte count fails the SEGMENTS output. If you blank on the encoding math during the live assessment, StealthCoder sits invisibly on your desktop as a safety net and gives you the working structure.
The problem
Simulate a durable string key-value store over an ordered batch of commands. The durable store is an append-only log split greedily across numbered segments, each with capacity 1024 bytes. Commands PUT key value: append a record, set the key to the value using last-write-wins semantics, and return OK. The value is the entire suffix after the second space and may be empty. GET key: return VALUE:value for a present key, or NOT_FOUND. RELOAD: discard the in-memory map, rebuild it by replaying every complete record in segment order, and return OK. SEGMENTS: return SEGMENTS:s1,s2,..., where each number is one segment's used-byte count. With no records, return SEGMENTS:. Record encoding Keys and values use printable ASCII, so each character occupies one byte. Encode a record as keyLength:keyvalueLength:value. A record is never split. Before an append that would make the current segment exceed 1024 bytes, start a new segment. Every record fits in one segment. Return one result string for each command in order. Function runSegmentedStore(commands: String[]) → String[] Examples Example 1 commands = ["PUT color blue","GET color","PUT color green","RELOAD","GET color","SEGMENTS"] return = ["OK","VALUE:blue","OK","OK","VALUE:green","SEGMENTS:27"] The two encoded records use 13 and 14 bytes. Reload replays both records, so the later value green wins. Example 2 commands = ["GET missing","SEGMENTS","PUT a " ,"RELOAD","GET a","SEGMENTS"] return = ["NOT_FOUND","SEGMENTS:","OK","OK","VALUE:","SEGMENTS:5"] An empty value is durable. Its record is 1:a0:: one digit for the key length, two colons, the one-character key, and one digit for the value length, for 5 bytes total. Constraints 1 <= commands.length <= 2000 Commands are well formed and use one of the four documented operation names. Keys are non-empty printable-ASCII strings of length at most 100 and contain no spaces. Values contain printable ASCII characters, may contain spaces, and have length at most 900. The total length of all command strings is at most 2 * 10^5. Every encoded record uses at most 1024 bytes.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that RELOAD is a replay, so you need to store actual records, not only sizes. Keep a list of segments, each a list of (key, value) records plus a used-byte count. On PUT, compute size as len(str(len(key))) + 1 + len(key) + len(str(len(value))) + 1 + len(value). Check example 2: 1:a0:: gives 5, which matches. If used + size exceeds 1024, open a new segment first. The first record in an empty log goes into segment one. Then update the live map. RELOAD clears the map and walks segments in order, last write wins. The common pitfall is parsing PUT with a plain split, which breaks values containing spaces or empty values. Split on the first two spaces only, and keep the trailing suffix intact, even when it's empty. SEGMENTS with no records returns the bare prefix with nothing after the colon. StealthCoder is the hedge if the parsing details slip under the clock.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Segmented Durable Key-Value Store 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass OpenAI's OA.
OpenAI reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Segmented Durable Key-Value Store FAQ
How hard is the Segmented Durable Key-Value Store question really?+
Easy to medium on algorithms, but annoying on details. There's no clever data structure. The risk is parsing PUT correctly and computing record byte sizes exactly. Most failures come from edge cases like empty values, values with spaces, and the segment overflow check, not from the core logic.
What's the trick to the record size calculation?+
Size is the digits of the key length, a colon, the key, the digits of the value length, a colon, and the value. Use the string length of the numbers, not a fixed width. Empty value gives 0 as one digit plus a colon, so 1:a0: totals 5 bytes.
How do I parse PUT when values can contain spaces?+
Split the command on the first space to get the operation, then on the next space to get the key. Everything after that is the value, even if it's empty or has more spaces. Don't use a generic split on whitespace, and don't trim trailing spaces.
When does a new segment start?+
Before appending, check whether current used bytes plus the new record size exceeds 1024. If so, start a new segment and put the record there. Exactly 1024 is allowed. Records never split across segments, and every record is guaranteed to fit in one.
How do I prepare for this in 48 hours?+
Write a small simulation by hand with a map, a list of segments, and a command dispatcher. Test the two examples, plus an empty value, a value with spaces, and a segment boundary at exactly 1024. Practice the string parsing, since that's where bugs hide.