Slab allocator

Write codeMedium30 minMicrosoft style

Your task

Simulate a fixed-size slab allocator with n_slots slots indexed 0..n_slots-1, all initially free. Process a list of operations. ["alloc"] returns the lowest-indexed free slot, marks it used, and that index is the allocation's handle; if no slot is free the alloc fails (no slot consumed). ["free", idx] frees slot idx if it is currently used (no-op if already free or out of range). After processing all ops, return a list of length n_slots where element i is 1 if slot i is used and 0 if free. n_slots >= 1; <= 10^5 ops.

Examples

slab_allocator(n_slots: int, ops: list[list]) -> list[int]
Example 1
Inputslab_allocator(3, [["alloc"], ["alloc"], ["free", 0], ["alloc"]])
Output[1, 1, 0]