Dynamic Array Data Structure - Interview Cake

Interview Cake by Exponent Toggle navigation Interview Cake by Exponent
  • Coding Questions
    • All Questions
    • Language-Specific Prep
      • Python Interview Questions
      • Java Interview Questions
      • Javascript Interview Questions
    • Company-Specific Prep
      • Google Interview Questions
      • Meta Interview Questions
      • Amazon Interview Questions
  • Tips
    • First coding interview? Start here.
    • General coding interview tips
    • How to get un-stuck
    • Beating impostor syndrome
    • 24 hours before your onsite
    • Why you're hitting dead ends
    • Best ways to practice
    • Organizing your interview timeline
    • Mastering behavioral questions
    • Common issues
  • Glossary
    • Big O Notation: , , etc
      • Big O Notation Basics
      • Big O Cheat Sheet
      • Logarithms
      • P vs. NP
    • Search Algorithms
      • Binary Search
      • Breadth-First Search
      • Depth-First Search
    • Sorting Algorithms
      • Big O Sorting Cheatsheet
      • Counting Sort
      • Insertion Sort
      • Selection Sort
      • Merge Sort
      • Quicksort
      • Heapsort
      • Radix Sort
      • Topological Sort
      • Stable Sort
    • Algorithm Heuristics
      • Brute Force Algorithms
      • Greedy Algorithms
      • Bottom-Up Algorithms
      • Overlapping Subproblems
      • Memoization
      • Just-In-Time vs. Ahead-Of-Time
      • Base Case for Recursive Functions
    • Data Structures
      • Data Structures Index
      • Data Structures for Coding Interviews
      • Tuple
      • Array
      • Dynamic Array
      • Hash Table
      • Linked List
      • Queue
      • Priority Queue
      • Stack
      • Heap
      • Trees
        • Overview of Trees
        • Balanced Tree
        • Binary Tree
        • Binary Search Tree
        • Ternary Search Tree
        • BST In-Order Traversal
        • Complete Binary Tree
        • Trie
      • Graph
      • Adjacency List
      • Bloom Filter
      • LRU Cache
    • Language-Specific Features
      • Short Circuit Evaluation
      • Garbage Collection
      • Closure
      • Array Slicing
      • Hashing
      • Mutable vs Immutable
      • Call Stack
      • Process Heap
      • In-Place Operation
      • C Data Structure Interview Questions
    • Binary & Bitwise Functions
      • Binary Numbers
      • Booleans
      • Bits and Number of Possibilities
      • Get Bit Value
      • Bitwise AND
      • Bitwise OR
      • Bitwise XOR
      • Bitwise NOT
      • Bit Shifting
      • Bit Manipulation
      • Integer Overflow
    • Other Concepts
      • Combinatorics Interview Questions
      • System Design Interview Questions
      • Triangular Series
      • The Modulus Operation
      • Consistent Hashing
      • Dijkstras Algorithm
      • Testing and QA Interview Questions
      • SQL Interview Questions
  • Coaching
  • Full Course
  • Get the full course
  • Log out
  • Log in to save progress
The dynamic array has a size of 3 and a capacity of 6. Dynamic Array Data Structure Other names: array list, growable array, resizable array, mutable array

Quick reference

Average Case Worst Case
space
lookup
append
insert
delete

A dynamic array is an array with a big improvement: automatic resizing.

One limitation of arrays is that they're fixed size, meaning you need to specify the number of elements your array will hold ahead of time.

A dynamic array expands as you add more elements. So you don't need to determine the size ahead of time.

Strengths:

  • Fast lookups. Just like arrays, retrieving the element at a given index takes time.
  • Variable size. You can add as many items as you want, and the dynamic array will expand to hold them.
  • Cache-friendly. Just like arrays, dynamic arrays place items right next to each other in memory, making efficient use of caches.

Weaknesses:

  • Slow worst-case appends. Usually, adding a new element at the end of the dynamic array takes time. But if the dynamic array doesn't have any room for the new item, it'll need to expand, which takes time.
  • Costly inserts and deletes. Just like arrays, elements are stored adjacent to each other. So adding or removing an item in the middle of the array requires "scooting over" other elements, which takes time.

In Java

In Java, dynamic arrays are called ArrayLists.

Here's what they look like:

List<Integer> gasPrices = new ArrayList<>(); gasPrices.add(346); gasPrices.add(360); gasPrices.add(354);

Size vs. Capacity

When you allocate a dynamic array, your dynamic array implementation makes an underlying fixed-size array. The starting size depends on the implementation—let's say our implementation uses 10 indices. Now say we append 4 items to our dynamic array. At this point, our dynamic array has a length of 4. But the underlying array has a length of 10.

We'd say this dynamic array's size is 4 and its capacity is 10. The dynamic array stores an endIndex to keep track of where the dynamic array ends and the extra capacity begins.

A dynamic array with a size of 4 and a capacity of 10. The end_index is located at index 4.

Doubling Appends

What if we try to append an item but our array's capacity is already full?

To make room, dynamic arrays automatically make a new, bigger underlying array. Usually twice as big.

Why not just extend the existing array? Because that memory might already be taken by another program.

Each item has to be individually copied into the new array.

Each element from the old dynamic array is copied into the new dynamic array.

Copying each item over costs time! So whenever appending an item to our dynamic array forces us to make a new double-size underlying array, that append takes time.

That's the worst case. But in the best case (and the average case), appends are just time.

Amortized cost of appending

  1. The time cost of each special "doubling append" doubles each time.
  2. At the same time, the number of appends you get until the next doubling append also doubles.

These two things sort of "cancel out," and we can say each append has an average cost or amortized cost of .

Given this, in industry we usually wave our hands and say dynamic arrays have a time cost of for appends, even though strictly speaking that's only true for the average case or the amortized cost.

Share Tweet Share

See also:

  • Array
  • Linked List

Interview coming up?

Get the free 7-day email crash course. You'll learn how to think algorithmically, so you can break down tricky coding interview questions.

No prior computer science training necessary—we'll get you up to speed quickly, skipping all the overly academic stuff.

No spam. One-click unsubscribe whenever.

You're in! Head over to your email inbox right now to read day one!

Dynamic Array Coding Interview Questions

Apple Stocks »

Figure out the optimal buy and sell time for a given stock, given its prices yesterday. keep reading »

Product of All Other Numbers »

For each number in an array, find the product of all the other numbers. You can do it faster than you'd think! keep reading »

Highest Product of 3 »

Find the highest possible product that you can get by multiplying any 3 numbers from an input array. keep reading »

Making Change »

Write a function that will replace your role as a cashier and make everyone rich or something. keep reading »

Find in Ordered Set »

Given an array of numbers in sorted order, how quickly could we check if a given number is present in the array? keep reading »

Find Rotation Point »

I wanted to learn some big words to make people think I'm smart, but I messed up. Write a function to help untangle the mess I made. keep reading »

Reverse String in Place »

Write a function to reverse a string in place. keep reading »

Reverse Words »

Write a function to reverse the word order of a string, in place. It's to decipher a supersecret message and head off a heist. keep reading »

Parenthesis Matching »

Write a function that finds the corresponding closing parenthesis given the position of an opening parenthesis in a string. keep reading »

Bracket Validator »

Write a super-simple JavaScript parser that can find bugs in your intern's code. keep reading »

Permutation Palindrome »

Check if any permutation of an input string is a palindrome. keep reading »

Recursive String Permutations »

Write a recursive function of generating all permutations of an input string. keep reading »

Top Scores »

Efficiently sort numbers in an array, where each number is below a certain maximum. keep reading »

Which Appears Twice »

Find the repeat number in an array of numbers. Optimize for runtime. keep reading »

In-Place Shuffle »

Do an in-place shuffle on an array of numbers. It's trickier than you might think! keep reading »

Cafe Order Checker »

Write a function to tell us if cafe customer orders are served in the same order they're paid for. keep reading »

Merge Sorted Arrays »

Write a function for consolidating cookie orders and taking over the world. keep reading »

All Questions

Want more coding interview help?

Check out interviewcake.com for more advice, guides, and practice questions.

Subscribe to our weekly question email list »
Programming interview questions by company:
  • Google interview questions
  • Meta interview questions
  • Amazon interview questions
  • Uber interview questions
  • Microsoft interview questions
  • Apple interview questions
  • Netflix interview questions
  • Dropbox interview questions
  • eBay interview questions
  • LinkedIn interview questions
  • Oracle interview questions
  • PayPal interview questions
  • Yahoo interview questions
Programming interview questions by topic:
  • SQL interview questions
  • Testing and QA interview questions
  • Bit manipulation interview questions
  • Java interview questions
  • Python interview questions
  • Ruby interview questions
  • JavaScript interview questions
  • C++ interview questions
  • C interview questions
  • Swift interview questions
  • Objective-C interview questions
  • PHP interview questions
  • C# interview questions
Copyright © 2026 Exponent Labs LLC All rights reserved. 548 Market Street PMB 21689, San Francisco, CA US 94104 Privacy | Terms {"id":41256981,"username":"2026-03-06_17:37:54_zajy)&","email":null,"date_joined":"2026-03-06T17:37:54.880313+00:00","first_name":"","last_name":"","full_name":"","short_name":"friend","is_anonymous":true,"is_on_last_question":false,"percent_done":0,"num_questions_done":0,"num_questions_remaining":46,"is_full_access":false,"is_student":false,"first_payment_date":null,"last_payment_date":null,"num_free_questions_left":3,"terms_has_agreed_to_latest":false,"preferred_content_language":"","preferred_editor_language":"","is_staff":false,"auth_providers_human_readable_list":"","num_auth_providers":0,"auth_email":""} ×

Log in/sign up

With just a couple clicks.

| Google Auth | GitHub Auth

We'll never post on your wall or message your friends.

Where do I enter my password?

Actually, we don't support password-based login. Never have. Just the OAuth methods above. Why?

  1. It's easy and quick. No "reset password" flow. No password to forget.
  2. It lets us avoid storing passwords that hackers could access and use to try to log into our users' email or bank accounts.
  3. It makes it harder for one person to share a paid Interview Cake account with multiple people.
  4. Drew, happy user Whenever I have a friend ask me how I switched careers, I say that the confidence to take a technical interview came from Interview Cake. — Drew . . .

Tag » Add Element Dynamic Array Java