Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Recent Gate

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Expire calls outside the live window: The Recent Gate.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Recent call queue matches the clues
  2. 2Keep this true after every move: the queue contains exactly the calls in [t-3000,t]
  3. 3Reach the result within O(1) amortized per ping

Rules and pressure

  • Target cost: O(1) amortized per ping
  • State rule: the queue contains exactly the calls in [t-3000,t]

New words in this mission

Open a term for a plain-language explanation.
durable queue+

A waiting line that keeps work until a consumer finishes it. It absorbs bursts and lets failed work be retried.

Lesson 1 of 3

Live algorithm trace

Recent call queue

Complete execution
1 of 5
0
1
ping
1
100
2
3001
3
3002
4
6002

The first call is inside its own window.

1append the new timestamp
2compute cutoff = t - 3000
3while oldest < cutoff
4remove the oldest timestamp
5record queue size
t = 1queue = [1]count = 1
Truth to preserve / Cost target
Truth to preserve

the queue contains exactly the calls in [t-3000,t]

Cost target

O(1) amortized per ping

Increasing timestamps enter a queue. Before answering, remove every timestamp older than the inclusive 3000 millisecond window.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead