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 Hit Clock

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Merge counts into timestamp buckets: The Hit Clock.

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

How you win

  1. 1Recognize when Hit counter matches the clues
  2. 2Keep this true after every move: total equals the counts of all unexpired timestamp buckets
  3. 3Reach the result within O(1) amortized per event or query

Rules and pressure

  • Target cost: O(1) amortized per event or query
  • State rule: total equals the counts of all unexpired timestamp buckets

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

Hit counter

Complete execution
1 of 5
0
1
event
1
1
2
2
3
300
4
301

Create a bucket for the first hit at time 1.

1merge a hit into the newest timestamp bucket
2increment the live total
3on query, compute the cutoff
4expire buckets at or below cutoff
5subtract each expired bucket count
6return the live total
bucket = 1x1total = 1
Truth to preserve / Cost target
Truth to preserve

total equals the counts of all unexpired timestamp buckets

Cost target

O(1) amortized per event or query

Aggregate hits sharing a timestamp, then expire complete buckets outside the rolling window. A running total avoids summing the queue on every query.

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