Big O Gym › Problem

Big O Practice: Dynamic Array Push

Time and space complexity practice in Python and JavaScript. Concept tested: amortized analysis.

def build_list(n):
    arr = []
    for i in range(n):
        arr.append(i)
    return arr

Variables

  • n - number of pushes / final array size

Explanation

Each push is **O(1) amortized** - most are constant-time, but occasional resizes copy everything. Across `n` pushes the total copy work is bounded by 2n (geometric), so the function as a whole is **O(n)** time. The final array holds `n` elements, **O(n)** space. Worst-case-per-push is O(n), but amortized analysis is what matters here.

More Big O practice problems · Today's daily problem