Code Room
CodingHardcod-g1055
Subject Storage bitmap allocatorLevel Mid–Senior~35 minCommon in Storage & CDN interviewsIndustries Software development, Technology

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.