Class Solution
-
- All Implemented Interfaces:
public final class Solution3433 - Count Mentions Per User.
Medium
You are given an integer
numberOfUsersrepresenting the total number of users and an arrayeventsof sizen x 3.Each
events[i]can be either of the following two types:Message Event: <code>"MESSAGE", "timestamp<sub>i</sub>", "mentions_string<sub>i</sub>"</code>
Offline Event: <code>"OFFLINE", "timestamp<sub>i</sub>", "id<sub>i</sub>"</code>
Return an array
mentionswherementions[i]represents the number of mentions the user with idihas across allMESSAGEevents.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.
Note that a user can be mentioned multiple times in a single message event, and each mention should be counted separately.
Example 1:
Input: numberOfUsers = 2, events = ["MESSAGE","10","id1 id0","OFFLINE","11","0","MESSAGE","71","HERE"]
Output: 2,2
Explanation:
Initially, all users are online.
At timestamp 10,
id1andid0are mentioned.mentions = [1,1]At timestamp 11,
id0goes offline.At timestamp 71,
id0comes back online and"HERE"is mentioned.mentions = [2,2]Example 2:
Input: numberOfUsers = 2, events = ["MESSAGE","10","id1 id0","OFFLINE","11","0","MESSAGE","12","ALL"]
Output: 2,2
Explanation:
Initially, all users are online.
At timestamp 10,
id1andid0are mentioned.mentions = [1,1]At timestamp 11,
id0goes offline.At timestamp 12,
"ALL"is mentioned. This includes offline users, so bothid0andid1are mentioned.mentions = [2,2]Example 3:
Input: numberOfUsers = 2, events = ["OFFLINE","10","0","MESSAGE","12","HERE"]
Output: 0,1
Explanation:
Initially, all users are online.
At timestamp 10,
id0goes offline.At timestamp 12,
"HERE"is mentioned. Becauseid0is still offline, they will not be mentioned.mentions = [0,1]Constraints:
1 <= numberOfUsers <= 1001 <= events.length <= 100events[i].length == 3events[i][0]will be one ofMESSAGEorOFFLINE.<code>1 <= int(events1) <= 10<sup>5</sup></code>
The number of
id<number>mentions in any"MESSAGE"event is between1and100.0 <= <number> <= numberOfUsers - 1It is guaranteed that the user id referenced in the
OFFLINEevent is online at the time the event occurs.
-
-
Constructor Summary
Constructors Constructor Description Solution()
-