Google Interview Question

Code a self-growing array in java

Interview Answer

Anonymous

Dec 21, 2013

1. Create an array of specific length(say 10) and keep a track of the number of elements the array has. 2. When adding element, increment count and add element to array if space is available. If space is not available create an array of double the original length copy all elements in original element and then add the new element. 3. While deleting decrement count and if array is less than half full, create a new element of half the size and copy elements in the original array