Intuitive and easy-to-understand solution
IntuitionApproachI've used the map to have a count value for each users. And also before starting the count of each users, it's better to sort the event by its
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
I've used the map to have a count value for each users. And also before starting the count of each users, it's better to sort the event by its timeStamp.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
73 ms beats 26.67%

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
59.99 mb beats 93.33%


# Code
```typescript []
function countMentions(
  numberOfUsers: number,
  events: string[][]
): number[] {
  type UserStatus = {
    calledCount: number;
    isOnline: boolean;
    offlineTimeStamp: number;
  };

  // Initialize: Create a map to store the status of each user
  const userStatusMap = new Map<number, UserStatus>();
  for (let i = 0; i < numberOfUsers; i++) {
    userStatusMap.set(i, {
      calledCount: 0,
      isOnline: true,
      offlineTimeStamp: -1,
    });
  }

  // Sort events
  const sortedEvents = [...events].sort((a, b) => {
    const timeA = Number(a[1]);
    const timeB = Number(b[1]);
    if (timeA !== timeB) {
      return timeA - timeB;
    }
    // Process OFFLINE events first when timestamps are the same
    return a[0] === "OFFLINE" ? -1 : b[0] === "OFFLINE" ? 1 : 0;
  });

  // Process events
  for (const event of sortedEvents) {
    const [eventType, timestampStr, eventData] = event;
    const timestamp = Number(timestampStr);

    if (eventType === "OFFLINE") {
      // For OFFLINE events, set the specified user to offline
      const userId = Number(eventData);
      const userStatus = userStatusMap.get(userId)!;
      userStatus.isOnline = false;
      userStatus.offlineTimeStamp = timestamp;
    } else if (eventType === "MESSAGE") {
      // For MESSAGE events, process target users
      const mentionedUsers = eventData.split(" ");
      for (const mentioned of mentionedUsers) {
        if (mentioned === "ALL") {
          // Mention all users
          for (const [userId, userStatus] of userStatusMap.entries()) {
            userStatus.calledCount++;
          }
        } else if (mentioned === "HERE") {
          // Mention online users
          for (const [userId, userStatus] of userStatusMap.entries()) {
            if (
              userStatus.isOnline ||
              timestamp - userStatus.offlineTimeStamp >= 60
            ) {
              userStatus.calledCount++;
            }
          }
        } else if (mentioned.startsWith("id")) {
          // Mention specific users
          const userIds: number[] = mentioned
            .replace("id", "")
            .split(" ")
            .map(Number);
          for (const userId of userIds) {
            const userStatus = userStatusMap.get(userId)!;
            userStatus.calledCount++;
          }
        }
      }
    }
  }

  // Extract results
  const result: number[] = [];
  for (let i = 0; i < numberOfUsers; i++) {
    result.push(userStatusMap.get(i)!.calledCount);
  }
  return result;
}

```
['TypeScript']