Save 25%Black Friday: 25% off all plans — use code BLACKFRIDAY2026 at checkout. Ends Friday, Dec 4.Claim the deal

(This question is a variation of the LeetCode question 362. Design Hit Counter. If you haven't completed that question yet, it is recommended to solve it first.)

Design a message-event aggregator for a long-running system. Each event identifies a user and a chat and has a timestamp measured in whole seconds. For any user and query timestamp, report the number of recorded events in the trailing window of m seconds. The window is inclusive and equals [timestamp - m + 1, timestamp].

Events for the same user arrive in strictly increasing timestamp order. The system must remain memory-efficient over an indefinite runtime by discarding history that can no longer affect future queries.

Implement the ChatEventAggregator class:

  • ChatEventAggregator(int m) Initializes the aggregator with the positive window length m, measured in seconds.
Test Cases
Input
Output
Expected