Skip to content

Commit c2998fe

Browse files
authored
Create get-watched-videos-by-your-friends.py
1 parent c836cb7 commit c2998fe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n + vlogv), v is the number of the level videos
2+
# Space: O(w)
3+
4+
class Solution(object):
5+
def watchedVideosByFriends(self, watchedVideos, friends, id, level):
6+
"""
7+
:type watchedVideos: List[List[str]]
8+
:type friends: List[List[int]]
9+
:type id: int
10+
:type level: int
11+
:rtype: List[str]
12+
"""
13+
curr_level, lookup = set([id]), set([id])
14+
for _ in xrange(level):
15+
curr_level = set(j for i in curr_level for j in friends[i] if j not in lookup)
16+
lookup |= curr_level
17+
count = collections.Counter([v for i in curr_level for v in watchedVideos[i]])
18+
return sorted(count.keys(), key=lambda x: (count[x], x))

0 commit comments

Comments
 (0)