C++ | Sorting | String | Beats 98%
Code
# Code
```cpp []
class Solution {
public:
    vector<int> countMentions(int n, vector<vector<string>>& events) {

        auto cmp = [](const vector<string> &a, const vector<string> &b) -> bool {
            int timestamp1 = stoi(a[1]), timestamp2 = stoi(b[1]);

            if (timestamp1 != timestamp2) {
                return timestamp1 < timestamp2;
            } else {
                return a[0] == "OFFLINE" && b[0] == "MESSAGE";
            }

            return false;
        };

        vector<int> time(n, -1);
        vector<int> ans(n);

        sort(events.begin(), events.end(), cmp);

        for(auto &x: events){
            string s=x[0];
            int timestamp=stoi(x[1]);

            if(s=="OFFLINE"){
                int i=stoi(x[2]);
                time[i]=timestamp;
            }
            else{
                if(x[2]=="ALL"){
                    for(auto &a: ans) a++;
                }
                else if(x[2]=="HERE"){
                    for(int i=0; i<n; i++){
                        if(time[i]==-1) ans[i]++;
                        else if(timestamp>=time[i]+60){
                            ans[i]++;
                        }
                    }
                }
                else{
                    vector<int> user;
                    string temp="";
                    string str=x[2];
                    bool flag=false;
                    for(int i=0; i<str.size(); i++){
                        if(str[i]=='d'){
                            flag=true;
                            continue;
                        }
                        else if(str[i]==' '){
                            flag=false;
                            int d=stoi(temp);
                            ans[d]++;
                            temp="";
                        }

                        if(flag){
                            temp.push_back(str[i]);
                        }

                        if(i==str.size()-1){
                            int d=stoi(temp);
                            ans[d]++;
                        }
                    }
                }
            }
        }

        return ans;
    }
};
```
['Array', 'String', 'Sorting', 'Simulation', 'C++']