Copies made by a growing array
A dynamic array starts with capacity and no elements. Appending to a full array allocates a new buffer of twice the capacity and copies every existing element across (one copy per element), then writes the new element. You append elements. How many element copies (not counting the writes of new elements) are made in total?
Show hints (2)+
- A resize happens exactly when the current size is a power of two.
- List the sizes that trigger a resize before the 1000th append and add them.
Answer
Reveal answer →Final answer
1023
Create a free account to see the full worked solution and track your progress.
Interview format: Prop Trading