Data Structures19 sections · 729 units
Open in Course

Lessons from Recent Calls

Queue as window

What did you learn?

1.1. Queues naturally maintain a "sliding window" of elements. New elements enter at the back, old ones leave from the front.

2.2. Amortized analysis: even though the while loop can run multiple times per call, each element is enqueued and dequeued exactly once across all calls.

3.3. This pattern appears whenever you need to track "recent" items within some constraint. But queues have a limitation: you can only access the front. What if you need both ends?