LeetCode Challenge Day 88 β 3433. Count Mentions Per User
Nitin Ahirwal / December 12, 2025
Hey folks π
This is Day 88 of my LeetCode streak π
Today's problem is 3433. Count Mentions Per User β a clean simulation challenge that tests ordering of events and status tracking.
π Problem Statement
You are given:
numberOfUsers- A list of
events, each being either:- MESSAGE timestamp tokens
- OFFLINE timestamp userId
Rules:
"ALL"β mentions all users (even offline)"HERE"β mentions only online users"idX"β mentions user X explicitly- OFFLINE lasts 60 time units
- All users start online
- If an OFFLINE and MESSAGE occur at the same time β OFFLINE is processed first
Goal:
Return an array mentions[] where mentions[i] is the total number of mentions for user i.
π‘ Intuition
This is a time-based simulation.
We must:
- Process events in chronological order
- Apply OFFLINE before MESSAGE at the same timestamp
- Track each userβs online state using:
offlineUntil[user] = time when user becomes online - For each message, interpret tokens:
ALL: everyone gets a mentionHERE: only users currently online get a mentionidX: explicit mention regardless of status
Once we get the ordering and user state tracking right, the simulation becomes straightforward.
π Approach
- Parse and sort events
Sort by:
- timestamp ascending
- OFFLINE before MESSAGE
-
Maintain:
offlineUntil[user] = time -
For each event:
- OFFLINE β mark user offline for 60 time units
- MESSAGE β parse tokens and increment mention counts
- Return the
mentions[]array.
β±οΈ Complexity Analysis
-
Time Complexity:
O(n * users)β worst case: each message iterates through all users -
Space Complexity:
O(users)β for tracking offline state and mentions
π§βπ» Code (JavaScript)
/**
* @param {number} numberOfUsers
* @param {string[][]} events
* @return {number[]}
*/
var countMentions = function(numberOfUsers, events) {
// parse events into objects with numeric timestamp
const parsed = events.map(e => ({
type: e[0],
timestamp: parseInt(e[1], 10),
data: e[2]
}));
// sort by timestamp asc; for same timestamp, OFFLINE before MESSAGE
parsed.sort((a, b) => {
if (a.timestamp !== b.timestamp) return a.timestamp - b.timestamp;
if (a.type === b.type) return 0;
return (a.type === "OFFLINE") ? -1 : 1;
});
const mentions = new Array(numberOfUsers).fill(0);
const offlineUntil = new Array(numberOfUsers).fill(0);
for (const ev of parsed) {
const t = ev.timestamp;
if (ev.type === "OFFLINE") {
const id = parseInt(ev.data, 10);
offlineUntil[id] = t + 60;
} else { // MESSAGE
const tokens = ev.data.trim().split(/\s+/);
for (const token of tokens) {
if (token === "ALL") {
for (let i = 0; i < numberOfUsers; i++) mentions[i]++;
} else if (token === "HERE") {
for (let i = 0; i < numberOfUsers; i++) {
if (offlineUntil[i] <= t) mentions[i]++;
}
} else if (token.startsWith("id")) {
const idNum = parseInt(token.slice(2), 10);
if (!Number.isNaN(idNum) && idNum >= 0 && idNum < numberOfUsers) {
mentions[idNum]++;
}
}
}
}
}
return mentions;
};
π― Reflection
This problem is a great reminder that:
-
Correct event ordering matters
-
State tracking can be simple but must be precise
-
Small simulation problems become trivial with the right structure
That wraps up Day 88 of my LeetCode challenge!
Onwards to Day 89 π₯
Happy Coding π¨βπ»