Imagine you're building a chat monitoring system for a social platform! Your task is to track how many times each user gets mentioned across all messages.
You're given numberOfUsers representing the total number of users and an array events containing two types of events:
๐จ Message Events
["MESSAGE", "timestamp", "mentions_string"] - A message was sent at the given timestamp with mentions. The mentions can be:
id<number>- Mentions specific user ID (e.g., "id0 id2 id0" mentions user 0 twice and user 2 once)ALL- Mentions every single userHERE- Mentions only currently online users
๐ Offline Events
["OFFLINE", "timestamp", "user_id"] - User goes offline for exactly 60 time units (returns online at timestamp + 60)
Goal: Return an array where result[i] = total mentions for user i across all MESSAGE events.
Note: All users start online, and status changes are processed before messages at the same timestamp.
Input & Output
Visualization
Time & Space Complexity
O(n log n) for sorting events, O(m) for processing all mention tokens across all messages
O(n) for offline tracking data structures, O(u) for result array where u = numberOfUsers
Constraints
- 1 โค numberOfUsers โค 105
- 0 โค events.length โค 105
- Each event has exactly 3 elements
- 0 โค timestampi โค 109
- For OFFLINE events: 0 โค user_id โค numberOfUsers - 1
- mentions_string contains only valid tokens separated by single spaces
- Status changes are processed before messages at the same timestamp