- 1 current stop: learning
- 2 upcoming
- 3 upcoming
- 4 upcoming
- 5 upcoming
Finish after stop 5
Stop 1 of 5 · Pump station at the trailhead
Trick to keep in mind+3 XP
Refill lazily: elapsed time times rate, capped, only when someone knocks.
A bucket does not need a clock ticking for every key. When a request arrives, work out how much time has passed since the last update, add that much refill, and clamp at capacity. This costs two numbers of state, cannot drift, and avoids a million timers. A periodic full reset would bring back the boundary problem.
tokens = min(capacity, tokens + (now - last) * rate)
last = nowRead it once, then a question tests whether the trick stuck.