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
- 1Recognize when Hit counter matches the clues
- 2Keep this true after every move: total equals the counts of all unexpired timestamp buckets
- 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 execution1 of 5
0
1
event
1
1
2
2
3
300
4
301
Create a bucket for the first hit at time 1.
1
merge a hit into the newest timestamp bucket2
increment the live total3
on query, compute the cutoff4
expire buckets at or below cutoff5
subtract each expired bucket count6
return the live totalbucket = 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?