Get Watched Videos by Your Friends LeetCode solution in Python

1
class Solution:
2
def watchedVideosByFriends(
3
self,
4
watchedVideos: List[List[str]],
5
friends: List[List[int]],
6
id: int,
7
level: int,
8
) -> List[str]:
9
q = [id]
10
vis = set([id])
11
l = 0
12
while l < level:
13
new_q = []
14
for x in q:
15
for friend in friends[x]:
16
if not friend in vis:
17
vis.add(friend)
18
new_q.append(friend)
19
q = new_q
20
l += 1
21
a = Counter()
22
for x in q:
23
for vids in watchedVideos[x]:
24
a[vids] += 1
25
A = sorted([[a[x], x] for x in a])
26
return [x[1] for x in A]

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0