✅ ⟣ Java Solution ⟢
Code
# Code
```java []
class Solution {
    public int[] countMentions(int numberOfUsers, List<List<String>> events) {
        Collections.sort(events, (a,b)->{
            int time1 = Integer.parseInt(a.get(1)), time2 = Integer.parseInt(b.get(1));
            if(time1 == time2) {
                if(a.get(0).equals("OFFLINE") && b.get(0).equals("MESSAGE")) {
                    return -1;
                }
            }
            return Integer.parseInt(a.get(1)) - Integer.parseInt(b.get(1));
        });
        
        int ans[] = new int[numberOfUsers];
        int usertimestamp[] = new int[numberOfUsers];
        
        for(List<String> event : events) {
            String msg = event.get(0);
            int time = Integer.parseInt(event.get(1));
            if(msg.equals("OFFLINE")) {
                usertimestamp[Integer.parseInt(event.get(2))] = time+60;
                
            } else {
                String mentions_string = event.get(2);
                if(mentions_string.equals("ALL")) {
                    for(int i=0; i<numberOfUsers; i++) {
                        ans[i]++;
                    }
                    
                } else if(mentions_string.equals("HERE")) {
                    for(int i=0; i<numberOfUsers; i++) {
                        if(usertimestamp[i] <= time) ans[i]++;
                    }
                    
                } else {
                    for(String id: event.get(2).split(" ")) {
                        int curr = Integer.parseInt(id.substring(2));
                        ans[curr]++;
                    }
                }
            }
        }
        
        return ans;
    }
}
```
['Java']