Code RoomBitmap block allocator
HardPrep Room Coding #218

Bitmap block allocator

CodingStorage & CDNMid–Senior~35 min

A disk allocator manages `n_blocks` blocks via a free bitmap, all initially free. It serves contiguous allocations using first-fit. Process operations: ["alloc", size] finds the lowest starting index of a run of `size` consecutive free blocks, marks them used, and that start index is the allocation handle returned — if no such run exists the alloc fails and consumes nothing; ["free", start, size] marks the `size` blocks beginning at `start` as free (assume every free corresponds to a prior successful alloc of exactly that start/size). After all ops, return a list of the start indices returned by each successful alloc, in op order (failed allocs contribute nothing to this list). n_blocks >= 1; <= 5*10^3 ops; sizes >= 1.

Implement
bitmap_allocator(n_blocks: int, ops: list[list]) → list[int]
Examples
in[5,[["alloc",2],["alloc",2],["free",0,2],["alloc",1]]]out[0,2,0]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 35 min
InputExpectedGot
[5,[["alloc",2],["alloc",2],["free",0,2],["alloc",1]]][0,2,0]not run yetsample