3433. Count Mentions Per User Medium
1/**
2 * [3433] Count Mentions Per User
3 *
4 * You are given an integer numberOfUsers representing the total number of users and an array events of size n x 3.
5 * Each <code inline="">events[i] can be either of the following two types:
6 * <ol>
7 * Message Event: ["MESSAGE", "timestampi", "mentions_stringi"]
8 *
9 * This event indicates that a set of users was mentioned in a message at timestampi.
10 * The mentions_stringi string can contain one of the following tokens:
11 *
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 *
16 *
17 *
18 *
19 * Offline Event: ["OFFLINE", "timestampi", "idi"]
20 *
21 * This event indicates that the user idi had become offline at timestampi for 60 time units. The user will automatically be online again at time timestampi + 60.
22 *
23 *
24 * </ol>
25 * Return an array mentions where mentions[i] represents the number of mentions the user with id i has across all MESSAGE events.
26 * 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.
27 * Note that a user can be mentioned multiple times in a single message event, and each mention should be counted separately.
28 *
29 * <strong class="example">Example 1:
30 * <div class="example-block">
31 * Input: <span class="example-io">numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","71","HERE"]]</span>
32 * Output: <span class="example-io">[2,2]</span>
33 * Explanation:
34 * Initially, all users are online.
35 * At timestamp 10, id1 and id0 are mentioned. mentions = [1,1]
36 * At timestamp 11, id0 goes offline.
37 * At timestamp 71, id0 comes back online and "HERE" is mentioned. mentions = [2,2]
38 * </div>
39 * <strong class="example">Example 2:
40 * <div class="example-block">
41 * Input: <span class="example-io">numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","12","ALL"]]</span>
42 * Output: <span class="example-io">[2,2]</span>
43 * Explanation:
44 * Initially, all users are online.
45 * At timestamp 10, id1 and id0 are mentioned. mentions = [1,1]
46 * At timestamp 11, id0 goes offline.
47 * At timestamp 12, "ALL" is mentioned. This includes offline users, so both id0 and id1 are mentioned. mentions = [2,2]
48 * </div>
49 * <strong class="example">Example 3:
50 * <div class="example-block">
51 * Input: <span class="example-io">numberOfUsers = 2, events = [["OFFLINE","10","0"],["MESSAGE","12","HERE"]]</span>
52 * Output: <span class="example-io">[0,1]</span>
53 * Explanation:
54 * Initially, all users are online.
55 * At timestamp 10, id0 goes offline.
56 * At timestamp 12, "HERE" is mentioned. Because id0 is still offline, they will not be mentioned. mentions = [0,1]
57 * </div>
58 *
59 * Constraints:
60 *
61 * 1 <= numberOfUsers <= 100
62 * 1 <= events.length <= 100
63 * events[i].length == 3
64 * events[i][0] will be one of MESSAGE or OFFLINE.
65 * 1 <= int(events[i][1]) <= 10^5
66 * The number of id<number> mentions in any "MESSAGE" event is between 1 and 100.
67 * 0 <= <number> <= numberOfUsers - 1
68 * It is guaranteed that the user id referenced in the OFFLINE event is online at the time the event occurs.
69 *
70 */
71pub struct Solution {}
72
73// problem: https://leetcode.com/problems/count-mentions-per-user/
74// discuss: https://leetcode.com/problems/count-mentions-per-user/discuss/?currentPage=1&orderBy=most_votes&query=
75
76// submission codes start here
77
78impl Solution {
79 pub fn count_mentions(number_of_users: i32, events: Vec<Vec<String>>) -> Vec<i32> {
80 vec![]
81 }
82}
83
84// submission codes end
85
86#[cfg(test)]
87mod tests {
88 use super::*;
89
90 #[test]
91 fn test_3433() {
92 }
93}
94
Back
© 2025 bowen.ge All Rights Reserved.