Queues & Deques

Queues process elements in arrival order. Deques extend this with front and back operations.

38 lessons
109 min

Lessons

1. Intro

The FIFO principle

2m

2. Vocabulary - Queue

First in, first out

3m

3. Queue Visualization

See it work

2m

4. Queue Implementation

Array or linked list

3m

5. Where Queues Shine

Common applications

2m

6. BFS Overview

Level-order exploration

3m

7. Problem - Number of Recent Calls

Simple queue problem

3m1 problems

8. Recent Calls - Algorithm

Sliding time window

3m

9. Recent Calls - Implementation

Complete solution

3m1 problems

10. Lessons from Recent Calls

Queue as window

2m

11. Quiz: Queue Basics

FIFO behavior

2m1 problems

12. The Limitation of Queues

Single-ended access

2m

13. Vocabulary - Deque

Double-ended queue

3m

14. Deque Implementation

Built-in support

2m

15. The Sliding Window Maximum

A classic problem

3m

16. Vocabulary - Monotonic Deque

Ordered double-ended

3m

17. Why Monotonic Deque Works

The core idea

4m

18. Monotonic Deque Visualization

Step by step

4m

19. Problem - Sliding Window Maximum

Classic deque problem

3m1 problems

20. Sliding Max - Algorithm

Maintain monotonicity

3m

21. Sliding Max - Implementation

Complete solution

4m1 problems

22. Lessons from Sliding Max

Key patterns

3m

23. Quiz: Monotonic Deque

Maintenance rules

2m1 problems

24. Sliding Window Minimum

The mirror problem

2m

25. A Harder Problem

Prefix sum + deque

3m1 problems

26. Shortest Subarray - The Idea

Using prefix sums

4m

27. Shortest Subarray - Algorithm

Two operations

4m

28. Shortest Subarray - Implementation

Complete solution

5m1 problems

29. Lessons from Shortest Subarray

Combined techniques

3m

30. Quiz: Deque vs Stack vs Queue

Choosing structures

2m1 problems

31. Deque vs Two Stacks

Alternative approach

2m

32. When to Use Deques

Problem signals

2m

33. Problem - Constrained Subsequence Sum

DP with deque

3m1 problems

34. Constrained Sum - DP Formulation

State and transition

3m

35. Constrained Sum - Implementation

DP with sliding max

4m1 problems

36. Lessons from Constrained Sum

DP optimization

3m

37. Quiz: DP Optimization

When deques help

2m1 problems

38. Section Recap

What we learned

3m

Practice Problems

1.
Queue at the SchoolCodeforceseasy

Perfect introduction to queue simulation where students swap positions based on simple rules.

2.

Excellent for understanding queue structure reconstruction from neighbor relationships.

3.
Valeriy and DequeCodeforcesmedium

Teaches deque operations with pattern recognition. Great for understanding how deques stabilize into cycles.

4.
Kefa and ParkCodeforcesmedium

BFS tree traversal using queue with state tracking. Perfect for learning queue-based graph exploration.

5.

Demonstrates how choosing front/back insertion affects final structure. Excellent for understanding inversion counts.

6.
Binary DequeCodeforcesmedium

Teaches optimal removal from deque ends to achieve target sum. Great introduction to deque manipulation.

7.
Queue (Walruses)Codeforcesmedium

Advanced queue problem requiring finding furthest younger elements. Teaches monotonic stack/deque optimization.

8.
Valid BFS?Codeforcesmedium

Verifies if a sequence represents valid BFS traversal. Essential for understanding BFS queue mechanics.

9.

BFS with priority queue to find lexicographically smallest path. Modified BFS with ordering requirements.

10.
Pictures with KittensCodeforceshard

Classic monotonic deque DP optimization. Teaches how to use deque to optimize range maximum queries in DP.

11.
Fill the BagCodeforceshard

Greedy problem with implicit queue of powers of two. Understanding bit manipulation with queue-like processing.

12.
OpenStreetMapCodeforceshard

2D sliding window maximum using monotonic deque in both dimensions. Ultimate monotonic deque technique mastery.

13.

Fundamental problem teaching queue FIFO principles by implementing with LIFO stacks. Amortized O(1) operations.

14.
Design Circular DequeLeetCodemedium

Teaches circular buffer concepts with wrap-around indexing using modulo arithmetic.

15.

THE canonical monotonic deque problem. Reduces O(nk) to O(n) using decreasing deque for potential maxima.

16.

Combines prefix sum with monotonic deque to handle negative numbers elegantly.

17.

Classic DP optimization reducing O(nk) to O(n) using monotonic deque for sliding window maximum in DP.

18.
Jump Game VILeetCodemedium

DP disguised as sliding window maximum. Monotonic deque optimizes finding best previous jump position.

19.

Advanced application using TWO monotonic deques (one for min, one for max) simultaneously.

20.

Mathematical transformation combined with monotonic deque for variable-width sliding window optimization.

Ready to start learning?

Access all 38 lessons with interactive content and progress tracking.