Sorting Easiest Approach🔥
IntuitionBasically, here we have to count mentions per user like if the user is messaging and mentioning user then count it. So, In this we will use a hash map
# Intuition
Basically, here we have to count mentions per user like if the user is messaging and mentioning user then count it. So, In this we will use a hash map to mark that user offline until some time i.e. timeStamp+60 because as question says the user will become online automatically after this much time.
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach:
1. Start
2. Sort the events based on timeStamp and if timeStamp is same then we want to consider first offline events so sort it based on that.
3. Iterate through events.
4. Consider events based on event Type.
- If event is Offline then we have to mark that particular user offline and update timeStamp also that means that user is offline until timeStamp+60.
- If event is MESSAGE then we have to check id either it is ALL , HERE or specific user id.
    - If it is ALL then we have to mark all users online and increment ans for all user id.
    - If it is HERE then we have to increment ans only for online users.
    - Otherwise we have to increment ans only for specific user ids.
5. Return ans.
6. End.
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity: O(n log(n)) 
    - Sorting takes O(n log(n)) time complexity.
    - For loop takes O(n) time Complexity.
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: O(n)
    - Due to unordered_map which stores only offline users and their offline until what time.
    - Due to ans vector of size numberOfUsers.
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    static bool cmp(vector<string>&a , vector<string>&b){
        if(stoi(a[1])==stoi(b[1])){
            return a[0]>b[0];
        }

        return stoi(a[1])<stoi(b[1]);
    }

    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        vector<int>ans(numberOfUsers,0);
        unordered_map<int,int>offlineUntil;
        sort(events.begin(),events.end(),cmp);

        for(auto x:events){
            string eventType=x[0]; //either it is message or offline
            int timeStamp=stoi(x[1]);

            if(eventType=="OFFLINE"){ //if user goes offline 
                int id = stoi(x[2]);
                offlineUntil[id]=timeStamp+60;
            }
            else{ //if user is messaging
                string mentionsString = x[2];
                if(mentionsString=="ALL"){
                    for(int id=0;id<numberOfUsers;id++){
                        ans[id]++;
                    }
                }
                else if(mentionsString=="HERE"){ //mentions all online users
                    for(int id=0;id<numberOfUsers;id++){
                        if(offlineUntil[id]<=timeStamp || offlineUntil[id]==0){
                            ans[id]++;
                        }
                    }
                }
                else{ //if particular user's id is mentioned
                    stringstream ss(mentionsString);
                    string token;
                    while(ss>>token){
                        int id = stoi(token.substr(2));
                        ans[id]++;
                    }
                }
            }
        }

        return ans;
    }
};
```
['C++']