Implement a Sliding-Window Rate/Anomaly Detector

Problem Given a stream of timestamped metric values, detect when the metric breaches a threshold over a sliding time window (e.g. sum/average/count over the last W seconds exceeds T).

Requirements

  • Ingest values as they arrive (streaming).
  • At each step, know the windowed aggregate and flag when it breaches the threshold.

Areas to design

  • Maintaining the window efficiently as old entries expire.
  • Which aggregate (count, sum, max) and how to update it in O(1) amortized.
  • Memory bound when the input rate is high.

Example

  • values over time → flag each window whose aggregate breaches the threshold.
added …
LeaderboardSalaryAccount