GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free

Free preview: 2 of 3 free topics used. You can open 1 more without an account.

Sign up free to unlock all 99
TopicsArrays and strings

Dynamic array

beginnerappend in O(1) amortized by doubling the capacity
  • just appended
  • copied over

size = 0 · empty

Capacity 2

0
1

Start with room for 2 values and size 0.

1 / 16

Operations (6/20)

  1. append(25)
  2. append(61)
  3. append(14)
  4. append(80)
  5. append(47)
  6. pop()
1int[] data = new int[2];
2int size = 0;
3
4void append(int x) {
5 if (size == data.length) {
6 int[] bigger = new int[data.length * 2];
7 for (int i = 0; i < size; i++) bigger[i] = data[i];
8 data = bigger;
9 }
10 data[size++] = x;
11}
12
13int pop() {
14 if (size == 0) throw new RuntimeException("empty");
15 return data[--size];
16}

Variables

size =
0
capacity =
2

Work done

Size
0
Values copied
0

Shortcuts: Space play/pause · ← → step · M sound