← Questions
Memory allocator: leftmost free block and free by owner
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A memory has n units, numbered 0 to n - 1, all free at the start. Process a list of operations in order, each producing one recorded value:
- Allocate
sizeunits for anowner: find the leftmost run ofsizeconsecutive free units, give all of them to the owner and record the run's first index, or record-1if no run is long enough. - Free by owner: release every unit the owner holds and record how many units were freed.
Return the recorded values. Start with a direct simulation, then discuss how to make allocation faster when the memory is large.
No official answer yet. Write yours on the right and run it.
Nothing published yet.
Sign in to submit your code; every attempt is kept here.
Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding
