Algorithm · DoorDash · Medium
A random allocator stores unassigned workers in an array. Its allocation routine is designed to run in $$O(1)$$ time. To remove one worker, it selects a random valid index i, performs a swap-and-pop operation: exchange the element at index i with the element at the final position, remove the last element, and return the worker that was selected. The array length should decrease by exactly one, and the returned worker should be unusable until the collection is refilled. This…
Checking your access…