Design Memory Allocator
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Simulate a memory of n consecutive units, indexed 0 to n - 1, all initially free. Implement Allocator(n):
- allocate(size, mID) finds the **leftmost** run of size consecutive free units, marks them as owned by mID, and returns the index of the first unit. If no such run exists, it returns -1 and changes nothing.
- freeMemory(mID) frees every unit owned by mID and returns how many units were freed (possibly 0).
The same mID can own several separate blocks; freeMemory releases all of them at once.
Examples
Constraints
- 1 <= n, size, mID <= 1000
- At most 1000 calls to `allocate` and `freeMemory`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.