Sort and Loop
Code
# Code
```python []
class Solution(object):
    def countMentions(self, numberOfUsers, events):
        """
        :type numberOfUsers: int
        :type events: List[List[str]]
        :rtype: List[int]
        """
        events = sorted(events, key = lambda x : (int(x[1]), x[0]=='MESSAGE'))
        print(events)
        online = set()
        offline = set()
        # stores offline id as key and timestamp as value
        offline_times = defaultdict()
        # stores id as key and number of mentions as value
        mentions = defaultdict()
        for i in range(numberOfUsers):
            online.add(i)
            mentions[i] = 0
        for event in events:
            timestamp = int(event[1])
            for key, val in offline_times.items():
                if val <= timestamp - 60:
                    online.add(key)
                    if key in offline:
                        offline.remove(key)
            if event[0] == 'MESSAGE':
                if event[2] == 'ALL':
                    for j in range(numberOfUsers):
                        mentions[j] += 1
                elif event[2] == 'HERE':
                    for k in range(numberOfUsers):
                        if k in online:
                            mentions[k] += 1
                else:
                    ids = event[2].split(' ')
                    for val in ids:
                        mentions[int(val[2:])] += 1
            else:
                offline_times[int(event[2])] = int(event[1]) 
                offline.add(int(event[1]))
                if int(event[2]) in online:
                    online.remove(int(event[2]))
        print(mentions)
        return mentions.values()


        
        
```
['Python']