|
| 1 | +3433\. Count Mentions Per User |
| 2 | + |
| 3 | +Medium |
| 4 | + |
| 5 | +You are given an integer `numberOfUsers` representing the total number of users and an array `events` of size `n x 3`. |
| 6 | + |
| 7 | +Each `events[i]` can be either of the following two types: |
| 8 | + |
| 9 | +1. **Message Event:** <code>["MESSAGE", "timestamp<sub>i</sub>", "mentions_string<sub>i</sub>"]</code> |
| 10 | + * This event indicates that a set of users was mentioned in a message at <code>timestamp<sub>i</sub></code>. |
| 11 | + * The <code>mentions_string<sub>i</sub></code> string can contain one of the following tokens: |
| 12 | + * `id<number>`: where `<number>` is an integer in range `[0,numberOfUsers - 1]`. There can be **multiple** ids separated by a single whitespace and may contain duplicates. This can mention even the offline users. |
| 13 | + * `ALL`: mentions **all** users. |
| 14 | + * `HERE`: mentions all **online** users. |
| 15 | +2. **Offline Event:** <code>["OFFLINE", "timestamp<sub>i</sub>", "id<sub>i</sub>"]</code> |
| 16 | + * This event indicates that the user <code>id<sub>i</sub></code> had become offline at <code>timestamp<sub>i</sub></code> for **60 time units**. The user will automatically be online again at time <code>timestamp<sub>i</sub> + 60</code>. |
| 17 | + |
| 18 | +Return an array `mentions` where `mentions[i]` represents the number of mentions the user with id `i` has across all `MESSAGE` events. |
| 19 | + |
| 20 | +All users are initially online, and if a user goes offline or comes back online, their status change is processed _before_ handling any message event that occurs at the same timestamp. |
| 21 | + |
| 22 | +**Note** that a user can be mentioned **multiple** times in a **single** message event, and each mention should be counted **separately**. |
| 23 | + |
| 24 | +**Example 1:** |
| 25 | + |
| 26 | +**Input:** numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","71","HERE"]] |
| 27 | + |
| 28 | +**Output:** [2,2] |
| 29 | + |
| 30 | +**Explanation:** |
| 31 | + |
| 32 | +Initially, all users are online. |
| 33 | + |
| 34 | +At timestamp 10, `id1` and `id0` are mentioned. `mentions = [1,1]` |
| 35 | + |
| 36 | +At timestamp 11, `id0` goes **offline.** |
| 37 | + |
| 38 | +At timestamp 71, `id0` comes back **online** and `"HERE"` is mentioned. `mentions = [2,2]` |
| 39 | + |
| 40 | +**Example 2:** |
| 41 | + |
| 42 | +**Input:** numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","12","ALL"]] |
| 43 | + |
| 44 | +**Output:** [2,2] |
| 45 | + |
| 46 | +**Explanation:** |
| 47 | + |
| 48 | +Initially, all users are online. |
| 49 | + |
| 50 | +At timestamp 10, `id1` and `id0` are mentioned. `mentions = [1,1]` |
| 51 | + |
| 52 | +At timestamp 11, `id0` goes **offline.** |
| 53 | + |
| 54 | +At timestamp 12, `"ALL"` is mentioned. This includes offline users, so both `id0` and `id1` are mentioned. `mentions = [2,2]` |
| 55 | + |
| 56 | +**Example 3:** |
| 57 | + |
| 58 | +**Input:** numberOfUsers = 2, events = [["OFFLINE","10","0"],["MESSAGE","12","HERE"]] |
| 59 | + |
| 60 | +**Output:** [0,1] |
| 61 | + |
| 62 | +**Explanation:** |
| 63 | + |
| 64 | +Initially, all users are online. |
| 65 | + |
| 66 | +At timestamp 10, `id0` goes **offline.** |
| 67 | + |
| 68 | +At timestamp 12, `"HERE"` is mentioned. Because `id0` is still offline, they will not be mentioned. `mentions = [0,1]` |
| 69 | + |
| 70 | +**Constraints:** |
| 71 | + |
| 72 | +* `1 <= numberOfUsers <= 100` |
| 73 | +* `1 <= events.length <= 100` |
| 74 | +* `events[i].length == 3` |
| 75 | +* `events[i][0]` will be one of `MESSAGE` or `OFFLINE`. |
| 76 | +* <code>1 <= int(events[i][1]) <= 10<sup>5</sup></code> |
| 77 | +* The number of `id<number>` mentions in any `"MESSAGE"` event is between `1` and `100`. |
| 78 | +* `0 <= <number> <= numberOfUsers - 1` |
| 79 | +* It is **guaranteed** that the user id referenced in the `OFFLINE` event is **online** at the time the event occurs. |
0 commit comments