Microsoft interview question

Given a dynamic array class, implement a "push front" function. The class has a size, a capacity, and an array. Example a = [1,2,3] a.pushfront(4) -> [4,1,2,3]

Interview Answer

Anonymous

Oct 28, 2016

You have to check if you still have place in your array. If not, resize it. After, start from the right and copy your elements one index further, and the insert the new element at the index 0. This is also a pretty easy question, you just have to thing of starting from the right.