You are given the total number of users and a list of event records.
Each user is initially online.
There are two types of events:
MESSAGE event:
"MESSAGE", timestamp, mentionText
The message mentions certain users.
mentionText may contain:
idX → mentions user X
ALL → mentions every user (online or offline)
HERE → mentions only users who are currently online
A user may appear multiple times and each occurrence counts.
OFFLINE event:
"OFFLINE", timestamp, userId
The user becomes offline for exactly 60 time units, and automatically becomes online again at timestamp + 60.
If a user’s status changes at the same timestamp as a message, process the status change first.
Return an array result where result[i] is the total times user i was mentioned.
Input: numberOfUsers = 3 events = [ ["MESSAGE","5","id0 id2 id0"], ["OFFLINE","6","2"], ["MESSAGE","7","HERE"], ["MESSAGE","67","HERE"] ]
Output: [3,1,1]
Explanation:
- At time 5 → id0 twice, id2 once → result = [2,0,1] - At time 6 → id2 goes offline. - At time 7 ("HERE") → only id0 and id1 are online → result = [3,1,1] - At time 66+1 = 67 → id2 is back online → "HERE" mentions all three users → result remains [3,1,1]
Input: numberOfUsers = 1 events = [["MESSAGE","10","ALL"]]
Output: [1]
Explanation:
Only one user exists, so they are mentioned once.
Input: numberOfUsers = 3 events = [["OFFLINE","10","1"],["MESSAGE","12","ALL"]]
Output: [1,1,1]
Explanation:
"ALL" mentions everyone including offline users.
Accepted:
Submission: