Java Easy Solution | Sorting
Sort the list and then check according to constraints.Code
Sort the list and then check according to constraints.
# Code
```java []
class Solution {
    public int[] countMentions(int numberOfUsers, List<List<String>> events) {
        if(numberOfUsers==0)
            return new int[0];
        int ans[]=new int[numberOfUsers];
        int time[]=new int[numberOfUsers];
        Arrays.fill(time,0);
        Collections.sort(events,(o1,o2)-> {
                if (Integer.parseInt(o1.get(1)) > Integer.parseInt(o2.get(1))) {
                    return 1;
                } else if (Integer.parseInt(o1.get(1)) < Integer.parseInt(o2.get(1))) {
                    return -1;
                }
            else if (Integer.parseInt(o1.get(1)) == Integer.parseInt(o2.get(1)))
                {
                    if(o1.get(0).contains("OFFLINE"))
                        return -1;
                    else
                        return 1;
                }
                return 0;
            });
        for(List<String> li:events)
            {
                String type=li.get(0);
                String t=li.get(1);
                String mention=li.get(2);
                if(type.contains("MESSAGE"))
                {
                    if(mention.contains("ALL"))
                    {
                        for(int i=0;i<numberOfUsers;i++)
                            {
                                ans[i]++;
                            }
                    }
                    else if(mention.contains("HERE"))
                    {
                        for(int i=0;i<numberOfUsers;i++)
                            {
                                if(time[i]==0 || Integer.parseInt(t)-time[i]>=60)
                                {    
                                    ans[i]++;
                                }
                            }
                    }
                    else
                    {
                        String ids[]=mention.split(" ");
                        for(int i=0;i<ids.length;i++)
                            {
                                String id=ids[i].substring(2);
                                ans[Integer.parseInt(id)]++;
                            }
                    }
                }
                if(type.contains("OFFLINE"))
                {
                time[Integer.valueOf(mention)]=Integer.valueOf(t);
                }
            }
        return ans;
    }
}
```
['Sorting', 'Java']