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: 1 of 3 free topics used. You can open 2 more without an account.

Sign up free to unlock all 99
TopicsStacks and queues

Queue

beginnerenqueue, dequeue, peek: all O(1)
  • just joined
  • front being read
head = tail = null
← front: served firstback: new values join →

An empty queue: head and tail both point to null.

1 / 17

Operations (8/20)

  1. enqueue(12)
  2. enqueue(45)
  3. enqueue(7)
  4. peek()
  5. dequeue()
  6. enqueue(30)
  7. dequeue()
  8. dequeue()
1class Queue {
2 Node head, tail; // Node: int val; Node next;
3
4 void enqueue(int x) {
5 Node n = new Node(x);
6 if (tail == null) head = tail = n;
7 else { tail.next = n; tail = n; }
8 }
9
10 int dequeue() {
11 if (head == null)
12 throw new RuntimeException("empty");
13 int x = head.val;
14 head = head.next;
15 if (head == null) tail = null;
16 return x;
17 }
18
19 int peek() {
20 if (head == null)
21 throw new RuntimeException("empty");
22 return head.val;
23 }
24}

Variables

head =
null
tail =
null

Work done

Size
0
Operations
0

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