Skip to content

Commit b2a6770

Browse files
authored
Create analyze-user-website-visit-pattern.py
1 parent 6601c4a commit b2a6770

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n^3)
2+
# Space: O(n^3)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def mostVisitedPattern(self, username, timestamp, website):
9+
"""
10+
:type username: List[str]
11+
:type timestamp: List[int]
12+
:type website: List[str]
13+
:rtype: List[str]
14+
"""
15+
lookup = collections.defaultdict(list)
16+
A = zip(timestamp, username, website)
17+
A.sort()
18+
for t, u, w in A:
19+
lookup[u].append(w)
20+
count = sum([collections.Counter(set(itertools.combinations(lookup[u], 3))) for u in lookup], collections.Counter())
21+
return list(min(count, key=lambda x: (-count[x], x)))

0 commit comments

Comments
 (0)