Company: Visa_18_jan
Difficulty: medium
Memory Allocator Memory Allocator Description You are given an array of integers memory consisting of 0s and 1s which indicates whether the corresponding memory unit is free or not. memory[i] = 0 means that the i th memory unit is free, and memory[i] = 1 means it's occupied. The memory is aligned with segments of 8 units, so all occupied memory blocks must start at an index divisible by 8 (e.g. 0, 8, 16, etc). 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 (i.e., find the left-most contiguous subarray of 0s, starting at a 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