Memory allocator: leftmost free block and free by owner

0
Remix

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:

  1. Allocate size units for an owner: find the leftmost run of size consecutive free units, give all of them to the owner and record the run's first index, or record -1 if no run is long enough.
  2. 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.

OpenAICodingLast asked Sep 2026
No answer yet. Write the first one; the best answer gets endorsed.