Skip to content

Commit

Permalink
Create count-mentions-per-user.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Jan 26, 2025
1 parent c5c51c3 commit c24c5ad
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Python/count-mentions-per-user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Time: O(eloge + e * n), e = len(events)
# Space: O(e + n)

# simulation
class Solution(object):
def countMentions(self, numberOfUsers, events):
"""
:type numberOfUsers: int
:type events: List[List[str]]
:rtype: List[int]
"""
result = [0]*numberOfUsers
lookup = [1]*numberOfUsers
events.sort(key=lambda x: (int(x[1]), x[0] == "MESSAGE"))
for m, t, s in events:
if m == "OFFLINE":
lookup[int(s)] = int(t)+60
continue
if s == "ALL":
for i in xrange(len(lookup)):
result[i] += 1
elif s == "HERE":
for i in xrange(len(lookup)):
if lookup[i] <= int(t):
result[i] += 1
else:
for idx in s.split():
result[int(idx[2:])] += 1
return result

0 comments on commit c24c5ad

Please sign in to comment.