Problem context and objectives
Mission briefing
Puzzle systems engineer · A game mechanic is behaving incorrectly
Separate active trips from route aggregates: The Transit Ledger.
Brute force may pass the demo but fail when the world fills with players.
How you win
- 1Recognize when Underground system design matches the clues
- 2Keep this true after every move: each completed trip contributes once to exactly one ordered route aggregate
- 3Reach the result within O(1) average per operation
Rules and pressure
- Target cost: O(1) average per operation
- State rule: each completed trip contributes once to exactly one ordered route aggregate
Lesson 1 of 3
Live algorithm trace
Underground system design
Complete execution1 of 5
0
in A@3
op
1
in B@8
2
out C@15
3
out C@22
4
avg A-C
Store rider 1 as active from station A at time 3.
1
check-in stores station and time by rider2
check-out removes the active rider3
form the ordered start-end route key4
add duration to route total5
increment route trip count6
average = total / countrider1 = A@3
Truth to preserve / Cost target
Truth to preserve
each completed trip contributes once to exactly one ordered route aggregate
Cost target
O(1) average per operation
Active riders map to their check-in station and time. Completed route pairs store total duration and trip count, making average queries constant time.
Your call · What should guide every step of this algorithm?