Reported October 2026
OpenAIsimulation

Memory Allocator

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

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

The OpenAI OA reported in October 2026 is Memory Allocator, and the trap isn't the allocation itself. It's what happens after a free. You get n bytes, a fixed strategy like first_fit, and a list of malloc and free operations that each return a string. Miss one edge case and half the outputs go wrong. This is a simulation problem with interval bookkeeping, and the spec is short enough that you'll want to skim it. Don't. If you blank mid-assessment, StealthCoder runs invisibly on your desktop and can hand you a working structure while you keep your head straight.

The problem

You are given a continuous block of n bytes, addressed from 0 to n - 1. Initially, every byte is free.
Implement simulateMemoryAllocator, which processes a list of allocator operations and returns one output string for each operation.
The allocation strategy is fixed for the whole run:

Examples
Example 1
n = 8
strategy = "first_fit"
operations = ["malloc 4", "malloc 4", "free 4", "malloc 3", "free 1", "free 0", "malloc 5"]
return = ["0", "4", "OK", "4", "INVALID", "OK", "-1"]
After freeing the block at 4, first fit reuses that lowest eligible address for malloc 3. free 1 is invalid because 1 is not the start of an allocated block. The final request fails because no contiguous free block has size 5.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The core is tracking free intervals and allocated blocks separately. Keep a map from start address to block size for allocated blocks. That map makes free validation trivial: if the address isn't a key, return INVALID. Free space is the gaps between allocated blocks, so for malloc, sort the allocated starts and scan the gaps, including the gap before the first block and after the last. With first_fit, you take the lowest address whose gap fits. Example 1 shows the pitfall: after free 4, the freed hole at 4 must be reusable, and adjacent free space has to count as one contiguous region. Double frees and freeing a mid-block address must return INVALID, not crash. Failed malloc returns -1. Constraints aren't given, so a simple scan per operation is the safe baseline. If you freeze on the gap logic during the live OA, StealthCoder is the hedge that gives you the scan.

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 Memory Allocator 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 OpenAI's OA.

OpenAI 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.

Memory Allocator FAQ

What's the trick in the OpenAI Memory Allocator problem?+

Treat free space as the gaps between allocated blocks, not as a separate list you have to merge. Store allocated blocks by start address, sort them, and scan gaps. Adjacent frees merge automatically because the gap is just the distance between neighbors, so no coalescing code is needed.

How hard is this OA really?+

Algorithmically it's easy. There's no clever data structure required. It's hard because of detail: exact output strings, INVALID cases, and gap boundaries. Candidates lose points on off-by-one errors at the start and end of the memory block, not on the idea.

What counts as INVALID for free?+

From the example, free 1 is INVALID because 1 isn't the start of an allocated block. So any address that isn't an exact allocated start fails. That should also cover freeing an address twice, since the block is gone after the first free. Check your handling of both.

How should I test it before submitting?+

Run Example 1 by hand first. Then add cases: malloc larger than n, free before any malloc, free twice, and malloc that exactly fills a hole. Also test a malloc that fits only in the tail gap after the last block.

How do I prepare in 48 hours?+

Write the first_fit version from scratch once, with a dict of allocated blocks and a sorted gap scan. Then think about how a different strategy would change only the choice of gap. Keep the allocator logic separate from strategy selection so changes stay small.

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

OA at OpenAI?
Invisible during screen share
Get it