Company: Visa_6nov
Difficulty: medium
Memory Allocation System Problem Description You're given an array of integers memory made up of 0s and 1s, showing whether each memory unit is currently free or in use. memory[i] = 0 means the i th unit is free, and memory[i] = 1 means it is occupied. Memory is divided into aligned segments of 8 units, so any block you occupy must begin at an index divisible by 8 (e.g., 0, 8, 16 , etc). You must service two kinds of requests: alloc X : Locate the left-most aligned run of X consecutive free units and mark them occupied (that is, find the left-most contiguous run of 0 s whose starting position start is divisible by 8 , and set all of those units to 1 ). If no aligned run of X free units exists, return -1 ; otherwise return the starting index of the newly allocated block, and tag every unit in that block with an ID drawn from a running counter (the counter begins at 1 and increments after each successful alloc). Note: X can exceed 8 , so a single block may span several segments. erase ID