AlgoFrames

Capacity after k appends

Warm-up · Trace the algorithm · about 4 min

A dynamic array starts empty with capacity 1 and doubles when full. Append 4, 8, 15, 16, 23, 42 and answer each question before the steps play.

Example 1

Input:

{"values":[4,8,15,16,23,42],"capacity":1}

Output:

8

Constraints

  • The trace uses the input shown.
  • The capacity doubles only when an append finds the block full.

Learn the idea first: Dynamic arrays: capacity, growth, amortized append, a visual lesson.

More Dynamic arrays: capacity, growth, amortized append problems