Best Optimised Simple Sorting & Hashing Solution
ApproachFirst Sort the array based on Timestamp after that perform operations which are askedComplexity
Time complexity: O(N log N)

Space complexity: O(N)
Code
# Approach
First Sort the array based on **Timestamp** after that perform operations which are asked

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

- Space complexity: O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        unordered_map<string, int> avaiableTime;
        int TotalMentioncnt = 0;
        vector<int> ans(numberOfUsers, 0);
        
        sort(events.begin(), events.end(), [](vector<string>& a, vector<string>& b){
            if(a[1] == b[1])
                return (a[2] != "HERE");
                
            return stoi(a[1]) <= stoi(b[1]);
        });
        
        
        for(auto ele : events) {
            if(ele[2] == "ALL") {
                TotalMentioncnt++;
                continue;
            }
            
            if(ele[2] == "HERE") {
                for(auto ids : avaiableTime) {
                    if(ids.second > stoi(ele[1]))
                        ans[stoi(ids.first)]--;
                }
                TotalMentioncnt++;
                continue;
            }
            
            stringstream ss(ele[2]);
            string t;
            
            if(ele[0] == "MESSAGE") {
                while (getline(ss, t, ' ')) {
                    if(avaiableTime[t] <= stoi(ele[1]))
                        ans[stoi(t.substr(2))]++;
                }
                
            } else {
                while (getline(ss, t, ' ')) {
                    avaiableTime[t] = stoi(ele[1]) + 60;
                }
            }
        }
        
        for(int i = 0; i < numberOfUsers; i++)
            ans[i] += TotalMentioncnt;
        
        return ans;
    }
};
```
['Hash Table', 'Sorting', 'Simulation', 'C++']