Skip to content

Practice Count Mentions Per User

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3433
LeetCode Problem

Count Mentions Per User

Problem Statement

All numberOfUsers users begin online. Process events in timestamp order. An OFFLINE event ["OFFLINE", timestamp, id] makes that user offline until timestamp + 60. A MESSAGE event ["MESSAGE", timestamp, mentions] uses either ALL for every user, HERE for currently online users, or space-separated id<number> tokens for explicit users, including offline ones. Count duplicate explicit tokens separately. At a shared timestamp, apply offline changes and automatic returns online before messages. Return the mention total for each user across all messages.

Source: Count Mentions Per User on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","71","HERE"]]
Output
[2,2]

# Example 2

Input
numberOfUsers = 2, events = [["MESSAGE","10","id1 id0"],["OFFLINE","11","0"],["MESSAGE","12","ALL"]]
Output
[2,2]

# Example 3

Input
numberOfUsers = 2, events = [["OFFLINE","10","0"],["MESSAGE","12","HERE"]]
Output
[0,1]

Constraints

1 <= numberOfUsers <= 100
1 <= events.length <= 100
events[i].length == 3
events[i][0] will be one of MESSAGE or OFFLINE.
1 <= int(events[i][1]) <= 10^5
The number of id<number> mentions in any "MESSAGE" event is between 1 and 100.
0 <= <number> <= numberOfUsers - 1
It is guaranteed that the user id referenced in the OFFLINE event is online at the time the event occurs.

Related LeetCode Problems

Practice more problems similar to Count Mentions Per User.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.