Company: Databrick
Difficulty: medium
Memory Management Queries Problem Description Your task is to perform two types of queries: alloc X : Find the left-most aligned memory block of X consecutive free memory units and mark these units as occupied (ie: find the left-most contiguous subarray of 0s, starting at the position start which is divisible by 8, and replace all these memory units with 1s). If there is no proper aligned memory block with X consecutive free units, return -1; otherwise return the index of the first position of the allocated block segment and assign an ID to every single element in the block, based on an atomic counter (the counter starts at 1 and is incremented on every successful alloc operation). Note: X may be greater than 8, so the block may cover more than one memory segment. erase ID : If there exists an allocated memory block with element ids equal to ID, free all its memory units (set all of the bits in the block to 0). Return the length of the deleted memory block. If there is no such ID or th