Google - Contiguous memory allocation in an Big Array
Anonymous User
756

I've been recently asked this question in the onsite interview:
You are required to design a memory allocation class for an bigArray, which will have below methods:

int bigArray[10000] -> Not necessarily int[], can be anything(Should not modify array)

int allocateSlice(int size){
 // allocate a contiguous slice of length size in the array and return the starting index from where data can be stored
}

int freeSlice(int startIndex){
 // de-allocate a contiguous slice starting at startIndex, with size it has been allocated earlier
}

I was able to come up with an approach but don't think it was scaleable and would pass all test cases!
Can you guys tell me your thoughts on possible solutions?

#Google #Design

Comments (2)