A dynamic array starts with capacity 0 and size 0. Pushing one element costs 1. If the array is full (size equals capacity) before the push, it first allocates a buffer with capacity max(1, 2 * capacity) and copies every existing element, which costs size extra. So a push into a full array costs size + 1.
Write pushCosts(n) that simulates n pushes and returns { total, worst }:
total: the sum of the costs of all n pushesworst: the largest cost paid by any single push
For n = 0 both are 0. The point of the exercise is the pair of numbers: worst grows with n, but total / n stays below 3.