OpenAI interview question

Implement a Memory Allocator, followup question afterwards

Interview Answer

Anonymous

22 June 2026

it was pretty much the same question as the one on Leetcode. there were two functions, malloc() and free() and I first implemented it with a linear scan solution, where we just found the first fit for the block. After implementing this O(n) solution, I implemented a best-fit strategy, where we found the smallest possible block that could fit the allocation, which I used heap in Python to solve this portion.