Bitmap block allocator
Your task
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.
Examples
bitmap_allocator(n_blocks: int, ops: list[list]) -> list[int]Example 1
Input
bitmap_allocator(5, [["alloc", 2], ["alloc", 2], ["free", 0, 2], ["alloc", 1]])Output
[0, 2, 0]