Design an in-memory hit counter that supports:
(
-
recordHit(timestamp) to log an event, and
(
-
getCountLast5Minutes(now) to return the number of events that occurred in the past 300 seconds. Assume timestamps are integer seconds and non-decreasing across calls. Explain how to expire outdated events efficiently without storing every hit individually, detail your data-structure choices and time/space trade-offs, target O(
-
amortized per operation with O(
-
space, and implement the API with unit tests.