Code RoomSlab allocator
MediumPrep Room Coding #210

Slab allocator

CodingStorage & CDNMid–Senior~30 min

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.

Implement
slab_allocator(n_slots: int, ops: list[list]) → list[int]
Examples
in[3,[["alloc"],["alloc"],["free",0],["alloc"]]]out[1,1,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 30 min
InputExpectedGot
[3,[["alloc"],["alloc"],["free",0],["alloc"]]][1,1,0]not run yetsample