Sort and simulate what ever asked for 
IntuitionApproachComplexity
Time complexity:

Space complexity:
CodeHere is an article of my last interview experience - A Journey to FAANG Company, I recomand
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```cpp []
    vector<int> extractIntegers(string& str) {
        vector<int> result;
        stringstream ss(str);
        string id;
        while (ss >> id) result.push_back(stoi(id.substr(2)));
        return result;
    }

    vector<int> countMentions(int numberOfUsers, vector<vector<string>>& events) {
        auto comp = [](vector<string>& a, vector<string>& b){
            if(stoi(a[1]) == stoi(b[1])) return a[0][0] > b[0][0];
            return stoi(a[1]) < stoi(b[1]);
        };
        vector<int> ans(numberOfUsers, 0), userStatus(numberOfUsers, 1);
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> pq;
        int all = 0;

        sort(events.begin(), events.end(), comp);
        for(int i = 0; i < events.size(); ++i){
            if(events[i][0] == "MESSAGE"){
                while(!pq.empty() && pq.top().first <= stoi(events[i][1])) { userStatus[pq.top().second]++; pq.pop(); }
                if(events[i][2] == "ALL") all++;
                else if(events[i][2] == "HERE"){
                    for(int i = 0; i < userStatus.size(); ++i) ans[i] += (userStatus[i] == 1)?1:0;
                }else{
                    vector<int> t = extractIntegers(events[i][2]);
                    for(int i: t) ans[i] += 1;
                }
            }else{
                pq.push({ stoi(events[i][1]) + 60, stoi(events[i][2])}); 
                userStatus[stoi(events[i][2])]--;
            }
        }
        for(int i = 0; i < userStatus.size(); ++i) ans[i] += all;
        return ans;
    }
};
```



---

<b>Here is an article of my last interview experience - A Journey to FAANG Company, I recomand you to go through this to know which all resources I have used & how I cracked interview at Amazon:
https://leetcode.com/discuss/interview-experience/3171859/Journey-to-a-FAANG-Company-Amazon-or-SDE2-(L5)-or-Bangalore-or-Oct-2022-Accepted

---
['C++']