#3433

Count Mentions Per User

specialist · 905 · lc medium +31 · 50.8% accepted · 391 likes · top 39%

Description

You are given an integer numberOfUsers and an array events of size n x 3.

Each events[i] is one of two types:

- Message Event: ["MESSAGE", "timestampi", "mentions_stringi"] — indicates users mentioned in a message at timestampi. The mention string may contain:
- id<number>: a specific user ID (duplicates allowed; offline users may also be mentioned).
- ALL: all users.
- HERE: all currently online users.

- Offline Event: ["OFFLINE", "timestampi", "idi"] — user idi goes offline at timestampi for 60 time units, returning online at timestampi + 60.

All users start online. Status changes at a given timestamp are processed before message events at the same timestamp.

Return an array mentions where mentions[i] is the total number of times user i was mentioned across all MESSAGE events. Each mention in a single event is counted separately.

Code

1
2
3