Skip to content
Get started

Copies made by a growing array

A dynamic array starts with capacity 11 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 10001000 elements. How many element copies (not counting the 10001000 writes of new elements) are made in total?

Show hints (2)+
  1. A resize happens exactly when the current size is a power of two.
  2. List the sizes that trigger a resize before the 1000th append and add them.

Answer

Reveal answer →

1023

Create a free account to see the full worked solution and track your progress.

Interview format: Prop Trading

Related questions