Count how many times each user is mentioned across a sequence of timestamped events, with special handling for active and all-users mentions.
You are given a set of users and a chronological list of events. Some events contain mentions that can refer to specific users by id, while others can target all users or only currently active users.
Your task is to process the events in time order and compute, for each user, how many times they are mentioned according to the rules of the problem. The exact mention semantics depend on the event type, but the core challenge is to aggregate counts correctly while handling ordering and time-based state changes.
Return the mention count for every user in user-id order.
Input Format
- The first input describes the users involved.
- The second input describes a list of events, each with a timestamp and a message or action type.
- Each event may mention one user, multiple users, all users, or all currently active users depending on its type.
- Events should be processed in increasing timestamp order, and ties should be handled consistently by the event ordering rules.
Output Format
- Return an integer array where the -th value is the number of mentions received by user .
- The result should include every user exactly once, in increasing user id order.
Constraints
- Event timestamps are within a sortable integer range.
- User ids are contiguous or otherwise indexable.
- The solution should be efficient enough to process all events in roughly linear or time, depending on ordering requirements.
Example 1
Input
users = 3 entries = [ [1, "MESSAGE", [0, 2]], [2, "ALL", []], [3, "MESSAGE", [1]], [4, "ACTIVE", [0, 1, 2]] ]
Output
[2, 2, 2]
Explanation
User 0 is mentioned in the first message and by the ACTIVE event. User 1 is mentioned in the third message and by the ACTIVE event. User 2 is mentioned in the first message and by the ALL event.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.