Custom comparator and regex_iterator brute-force (C++)
IntuitionWe should sort events by timestamp and if they are eqaul prioritize events with message type OFFLINE. Keep track of offline timestamps and whats left i
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We should sort events by timestamp and if they are eqaul prioritize events with message type OFFLINE. Keep track of offline timestamps and whats left is only implementation.
# Approach
<!-- Describe your approach to solving the problem. -->
Use inbuilt sort function and custom comparator, use regex and regex iterator for message type which notifys several ids.
# Complexity
- Time complexity: O(n^2)
<!-- 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> extractIds(const string& input) {
        vector<int> ids;
        regex pattern(R"(id(\d+))");
        sregex_iterator it(input.begin(), input.end(), pattern);
        sregex_iterator end;

        while (it != end) {
            ids.push_back(stoi((*it)[1].str()));
            ++it;
        }

        return ids;
    }

    vector<int> countMentions(int n, vector<vector<string>>& events) {
        sort(events.begin(), events.end(), [](vector <string> x, vector <string> y){
            if(stoi(x[1]) == stoi(y[1])){
                if(x[0] == "OFFLINE")
                    return true;
                if(y[0] == "OFFLINE")
                    return false;
            }
            return stoi(x[1]) < stoi(y[1]);
        });
        vector <int> ans (n, 0);
        vector <int> offline (n, 0);
        for(auto & it : events){
            if(it[0] == "OFFLINE")
                offline[stoi(it[2])] = stoi(it[1]) + 60;
            else{
                if(it[2] == "ALL"){
                    for(int i = 0; i < n; i++)
                        ans[i]++;
                }
                else if(it[2] == "HERE"){
                    for(int i = 0; i < n; i++)
                        if(offline[i] <= stoi(it[1]))
                            ans[i]++;
                }
                else {
                    vector <int> ids = extractIds(it[2]);
                    for(auto & id : ids){
                        ans[id]++;
                    }
                }             
            }
        }
        return ans;
    }
};
```
['C++']